:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --panel-3: #0b1220;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --border: #334155;
  --sidebar-width: 240px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--panel-3);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar h2 {
  margin: 0 0 1.5rem;
  font-size: 1.2rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.sidebar-nav a,
.sidebar-nav button {
  display: block;
  width: 100%;
  padding: 0.8rem 0.9rem;
  border-radius: 10px;
  text-decoration: none;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.95rem;
}

.sidebar-nav a:hover,
.sidebar-nav button:hover,
.sidebar-nav a.active {
  background: var(--panel);
  border-color: var(--border);
}

.main-content {
  flex: 1;
  min-width: 0;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}

main {
  padding: 1.5rem;
}

.grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1rem;
}

.stats {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.forms {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.tables {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  align-items: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  min-width: 0;
  overflow: hidden;
}

.card.wide {
  grid-column: span 2;
}

.card p {
  margin: 0.45rem 0;
}

h1,
h2,
h3 {
  margin-top: 0;
}

input,
select,
textarea,
button {
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

button {
  background: var(--accent);
  border: none;
  cursor: pointer;
  font-weight: bold;
}

.small {
  color: var(--muted);
  font-size: 0.85rem;
}

#customersTable,
#jobsTable,
#invoicesTable,
#outstandingTable,
#transactionsTable,
#expensesTable {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 520px;
  min-width: 0;
}

table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  table-layout: fixed;
}

th,
td {
  text-align: left;
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th {
  white-space: nowrap;
}

.truncate {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: top;
}

.status {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: bold;
  white-space: nowrap;
  background: #334155;
  color: #e5e7eb;
}

.status-paid {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
}

.status-open {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
}

.status-overdue {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
}

.status-cancelled {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
}

.clickable-row {
  cursor: pointer;
  transition: background 0.15s ease;
}

.clickable-row:hover td,
.clickable-nav-row:hover td {
  background: rgba(59, 130, 246, 0.08);
}

.clickable-nav-row td {
  transition: background 0.15s ease;
}

.empty-state {
  padding: 1rem 0;
}

.page-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.page-title {
  margin: 0;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
}

.login-card h1 {
  margin-bottom: 0.5rem;
}

.login-error {
  margin-top: 0.75rem;
  color: #fca5a5;
  font-size: 0.9rem;
}

.job-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.job-actions button {
  width: auto;
  min-width: 140px;
}

.danger-btn {
  background: #dc2626;
}

.danger-btn:hover {
  background: #b91c1c;
}

.inline-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.small-btn {
  width: auto;
  min-width: 72px;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
}

.stats .card div {
  font-weight: bold;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0 1rem;
}

.checkbox-row input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.nested-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.part-breakdown-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
  margin-bottom: 0.9rem;
  background: var(--panel);
}

.part-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 0.75rem;
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .card.wide {
    grid-column: span 1;
  }

  header {
    flex-direction: column;
    align-items: stretch;
  }

  table {
    table-layout: auto;
    min-width: 700px;
  }

  th,
  td {
    white-space: nowrap;
  }

  .part-grid {
    grid-template-columns: 1fr;
  }
}

.job-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.job-profit-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.job-main-sections {
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  align-items: start;
}

#jobInvoice,
#jobDescription {
  min-height: 48px;
}

@media (max-width: 900px) {
  .job-main-sections {
    grid-template-columns: 1fr;
  }

  .job-profit-grid,
  .job-summary-grid {
    grid-template-columns: 1fr;
  }
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.invoice-filter-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.invoice-filter-toggle {
  display: flex;
  align-items: end;
}

.report-filter-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.report-main-grid {
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  align-items: start;
}

.report-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

@media (max-width: 900px) {
  .report-main-grid {
    grid-template-columns: 1fr;
  }

  .report-card-header {
    flex-direction: column;
    align-items: stretch;
  }
}

.compact-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.compact-metrics-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.compact-two-col-grid {
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  align-items: start;
}

@media (max-width: 900px) {
  .compact-two-col-grid,
  .compact-summary-grid,
  .compact-metrics-grid {
    grid-template-columns: 1fr;
  }
}

.job-filter-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.bulk-job-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.bulk-job-actions {
  display: flex;
  align-items: end;
}

.transaction-filter-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.compact-two-col-grid {
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  align-items: start;
}

.json-block {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  font-size: 0.9rem;
  color: var(--text);
}

@media (max-width: 900px) {
  .compact-two-col-grid {
    grid-template-columns: 1fr;
  }
}

#loanRepaymentFields {
  display: none;
}

.quick-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
}

.logo img {
  height: 60px;
  object-fit: contain;
}