:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-muted: #f1f4f2;
  --ink: #1e2421;
  --muted: #68716d;
  --line: #d9dfdc;
  --primary: #f3c316;
  --primary-strong: #d7a900;
  --primary-ink: #201900;
  --accent: #c79300;
  --warning: #b26a00;
  --danger: #a63d40;
  --success: #25764b;
  --shadow: 0 14px 32px rgba(33, 42, 38, 0.09);
  --radius: 8px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --bg: #111312;
  --surface: #181c1a;
  --surface-muted: #232925;
  --ink: #f4f5f2;
  --muted: #aab2ad;
  --line: #303832;
  --primary: #f3c316;
  --primary-strong: #ffd84b;
  --primary-ink: #201900;
  --accent: #f3c316;
  --shadow: 0 18px 34px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.app {
  min-height: 100vh;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(246, 247, 244, 0.98)),
    repeating-linear-gradient(90deg, rgba(243, 195, 22, 0.12) 0, rgba(243, 195, 22, 0.12) 1px, transparent 1px, transparent 88px);
}

[data-theme="dark"] .login-shell {
  background:
    linear-gradient(180deg, rgba(17, 19, 18, 0.84), rgba(17, 19, 18, 0.98)),
    repeating-linear-gradient(90deg, rgba(243, 195, 22, 0.11) 0, rgba(243, 195, 22, 0.11) 1px, transparent 1px, transparent 88px);
}

.login-panel {
  width: min(100%, 460px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-row,
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: var(--primary);
  border: 1px solid rgba(243, 195, 22, 0.45);
  border-radius: var(--radius);
  background: rgba(243, 195, 22, 0.11);
}

.brand-logo {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: block;
  object-fit: cover;
  object-position: center 48%;
  border: 1px solid rgba(243, 195, 22, 0.45);
  border-radius: var(--radius);
  background: #111312;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.14);
}

.login-panel .brand-logo {
  width: 56px;
  height: 56px;
}

.brand-copy h1,
.brand-copy h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.2;
}

.brand-copy span {
  color: var(--muted);
  font-size: 0.88rem;
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span,
.fieldset-title {
  color: var(--ink);
  font-weight: 650;
  font-size: 0.88rem;
}

.field input,
.field select,
.field textarea,
.filter,
.date-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.filter:focus,
.date-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(243, 195, 22, 0.22);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-row.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  color: var(--ink);
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 13px;
  text-decoration: none;
  font-weight: 650;
  white-space: nowrap;
}

.btn:hover {
  border-color: #aeb9b4;
  background: var(--surface-muted);
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: var(--primary);
}

.btn.primary:hover {
  background: var(--primary-strong);
}

.btn.danger {
  color: var(--danger);
  border-color: rgba(166, 61, 64, 0.35);
}

.btn.danger:hover {
  background: #fff3f3;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.icon-only {
  width: 40px;
  padding: 0;
}

.btn.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.88rem;
}

.form-note,
.empty,
.login-hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.login-hint {
  margin: 18px 0 0;
}

.error {
  color: var(--danger);
  min-height: 20px;
  font-size: 0.9rem;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-button {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  text-align: left;
}

.nav-button svg {
  width: 18px;
  height: 18px;
}

.nav-button:hover,
.nav-button.active {
  background: var(--surface-muted);
  border-color: var(--line);
}

.nav-button.active {
  color: var(--accent);
  font-weight: 750;
}

.nav-badge {
  min-width: 22px;
  min-height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  color: #fff;
  background: var(--danger);
  font-size: 0.74rem;
  font-weight: 800;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.user-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
}

.user-chip strong {
  color: var(--ink);
}

.content {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand {
  display: none;
}

.page {
  padding: 22px;
  display: grid;
  gap: 18px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.page-title {
  margin: 0;
  font-size: 1.48rem;
  line-height: 1.2;
}

.page-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar {
  justify-content: space-between;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.summary-card,
.panel,
.table-panel,
.notice,
.record-card,
.form-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 22px rgba(33, 42, 38, 0.04);
}

.summary-card {
  padding: 15px;
  min-height: 108px;
  display: grid;
  align-content: space-between;
  gap: 12px;
}

.summary-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
}

.summary-value {
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.1;
}

.summary-foot {
  color: var(--muted);
  font-size: 0.84rem;
}

.summary-card.warn {
  border-color: rgba(178, 106, 0, 0.35);
  background: color-mix(in srgb, var(--surface) 86%, #f3c316);
}

.summary-card.danger {
  border-color: rgba(166, 61, 64, 0.28);
  background: color-mix(in srgb, var(--surface) 88%, #a63d40);
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 14px;
  align-items: start;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}

.panel {
  padding: 16px;
  min-width: 0;
}

.panel-title {
  margin: 0 0 12px;
  font-size: 1rem;
  line-height: 1.25;
}

.stack {
  display: grid;
  gap: 10px;
}

.list-row {
  display: grid;
  gap: 5px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.list-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.list-row:last-child {
  padding-bottom: 0;
}

.row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.row-main strong,
.record-title {
  overflow-wrap: anywhere;
}

.meta {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface-muted);
  color: #45504b;
  font-size: 0.78rem;
  font-weight: 750;
  white-space: nowrap;
}

.pill.green,
.status-paid,
.status-active,
.status-completed,
.status-approved,
.status-delivered,
.status-closed-won,
.status-active-client {
  color: #16623f;
  background: #e9f7ef;
}

.pill.blue,
.status-pending,
.status-in-progress,
.status-ready-to-start,
.status-sent,
.status-interested,
.status-demo-scheduled,
.status-proposal-sent,
.status-contacted {
  color: #245f9f;
  background: #eaf3ff;
}

.pill.amber,
.status-waiting,
.status-waiting-on-customer,
.status-discovery,
.status-draft,
.status-paused,
.status-review,
.status-cancel-soon,
.status-overdue,
.status-new-lead {
  color: #8a5200;
  background: #fff4df;
}

.pill.red,
.status-denied,
.status-cancelled,
.status-cancel,
.status-void,
.status-closed-lost,
.status-cancelled-client {
  color: #933436;
  background: #ffecec;
}

.progress {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4e9e6;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.progress.warn span {
  background: var(--warning);
}

.progress.danger span {
  background: var(--danger);
}

.table-panel {
  overflow: hidden;
}

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

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  font-weight: 800;
  background: var(--surface-muted);
}

td {
  color: var(--ink);
}

tr:last-child td {
  border-bottom: 0;
}

.cell-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.form-panel {
  padding: 16px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: stretch end;
  background: rgba(18, 23, 21, 0.42);
}

.drawer-panel {
  width: min(100%, 620px);
  height: 100%;
  background: var(--surface);
  overflow-y: auto;
  padding: 20px;
  box-shadow: -18px 0 34px rgba(20, 28, 24, 0.22);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.drawer-title {
  margin: 0;
  font-size: 1.15rem;
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.record-card {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.record-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.record-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
}

.record-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.invoice-workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 14px;
  align-items: start;
}

.invoice-form {
  gap: 14px;
}

.invoice-items {
  display: grid;
  gap: 10px;
}

.invoice-item-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(160px, 1.2fr) 86px 110px 88px 40px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.invoice-row-total {
  min-height: 42px;
  display: grid;
  align-content: center;
  gap: 2px;
}

.invoice-preview-panel {
  position: sticky;
  top: 86px;
}

.invoice-paper {
  --invoice-color: var(--primary);
  background: #fff;
  color: #202421;
  border: 1px solid #d9dfdc;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.invoice-accent {
  height: 10px;
  background: var(--invoice-color);
}

.invoice-head,
.invoice-meta-grid,
.invoice-total-grid {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.invoice-head {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  border-bottom: 1px solid #e4e8e5;
}

.invoice-brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.invoice-brand h2 {
  margin: 0 0 5px;
  font-size: 1.25rem;
}

.invoice-logo,
.invoice-logo-fallback {
  width: 76px;
  height: 76px;
  object-fit: cover;
  object-position: center 48%;
  border-radius: var(--radius);
  background: #111312;
  border: 1px solid rgba(243, 195, 22, 0.35);
}

.invoice-number-box {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.invoice-number-box strong {
  font-size: 1.45rem;
  text-transform: uppercase;
}

.invoice-meta-grid {
  grid-template-columns: minmax(0, 1fr) 180px;
}

.invoice-meta-grid strong {
  display: block;
  margin: 4px 0 8px;
}

.invoice-table-wrap {
  overflow-x: auto;
  padding: 0 24px 18px;
}

.invoice-table {
  min-width: 620px;
}

.invoice-table th {
  background: #f4f2e6;
  color: #3d3620;
}

.invoice-table th,
.invoice-table td {
  border-color: #e4e8e5;
}

.invoice-total-grid {
  grid-template-columns: minmax(0, 1fr) 250px;
  border-top: 1px solid #e4e8e5;
}

.invoice-total-grid p {
  margin: 6px 0 14px;
  color: #606963;
  line-height: 1.45;
}

.invoice-totals {
  display: grid;
  gap: 8px;
}

.invoice-totals div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.invoice-grand-total {
  border-top: 2px solid var(--invoice-color);
  padding-top: 10px;
  font-size: 1.2rem;
}

.notice {
  padding: 14px;
  display: grid;
  gap: 8px;
}

.notice.warning {
  background: color-mix(in srgb, var(--surface) 86%, #f3c316);
  border-color: rgba(178, 106, 0, 0.35);
}

.notice.danger {
  background: color-mix(in srgb, var(--surface) 88%, #a63d40);
  border-color: rgba(166, 61, 64, 0.28);
}

.notice.success {
  background: color-mix(in srgb, var(--surface) 88%, #25764b);
  border-color: rgba(37, 118, 75, 0.28);
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.permission-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #c8d0cc;
  transition: 0.18s ease;
}

.slider:before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: 0.18s ease;
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider:before {
  transform: translateX(20px);
}

.mobile-nav {
  display: none;
}

.hide {
  display: none !important;
}

.restricted {
  min-height: 360px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 28px;
}

.restricted .brand-mark {
  margin: 0 auto 14px;
}

@media (max-width: 1180px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-2,
  .grid-3,
  .record-grid {
    grid-template-columns: 1fr;
  }

  .invoice-workspace {
    grid-template-columns: 1fr;
  }

  .invoice-preview-panel {
    position: static;
  }
}

@media (max-width: 820px) {
  .shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 50;
    inset: 0 auto 0 0;
    width: min(86vw, 310px);
    transform: translateX(-103%);
    transition: transform 0.2s ease;
    box-shadow: 16px 0 30px rgba(18, 23, 21, 0.18);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-nav {
    display: inline-flex;
  }

  .topbar-brand {
    display: flex;
  }

  .topbar {
    padding: 12px 14px;
  }

  .page {
    padding: 16px;
  }

  .page-header,
  .toolbar {
    display: grid;
    gap: 12px;
  }

  .actions {
    width: 100%;
  }

  .actions .btn,
  .toolbar .btn {
    flex: 1 1 auto;
  }

  .summary-grid,
  .field-row,
  .field-row.three,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .invoice-item-row {
    grid-template-columns: 1fr;
  }

  .invoice-head,
  .invoice-meta-grid,
  .invoice-total-grid {
    grid-template-columns: 1fr;
  }

  .invoice-number-box {
    justify-items: start;
  }

  .drawer {
    place-items: stretch;
  }

  .drawer-panel {
    width: 100%;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .page-header,
  .summary-grid,
  .invoice-workspace > .panel:first-child,
  .invoice-preview-panel > .row-main {
    display: none !important;
  }

  .shell,
  .content,
  .page,
  .invoice-workspace,
  .invoice-preview-panel {
    display: block;
    padding: 0;
    margin: 0;
  }

  .invoice-preview-panel {
    border: 0;
    box-shadow: none;
  }

  .invoice-paper {
    border: 0;
    box-shadow: none;
    border-radius: 0;
  }
}

@media (max-width: 480px) {
  .login-shell {
    padding: 14px;
  }

  .login-panel {
    padding: 20px;
  }

  .summary-card {
    min-height: 94px;
  }

  .summary-value {
    font-size: 1.25rem;
  }

  .btn {
    white-space: normal;
  }
}
