:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #eeeeeb;
  --ink: #151515;
  --muted: #6b6b67;
  --line: #d9d9d4;
  --dark: #111111;
  --danger: #a61f1f;
  --success: #176b3a;
  --warning: #8a5b00;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.mobile-only { display: none; }
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.wrap { flex-wrap: wrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.w-100 { width: 100%; }


.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  background: #080808;
}
.login-hero {
  display: grid;
  place-items: center;
  padding: 50px;
  color: #fff;
  background: radial-gradient(circle at 50% 35%, #393939 0, #111 42%, #050505 72%);
  overflow: hidden;
}
.login-hero-content { text-align: center; width: min(680px, 100%); }
.login-logo {
  width: min(460px, 75%);
  max-height: 460px;
  object-fit: contain;
  border-radius: 50%;
  filter: drop-shadow(0 28px 50px rgba(0,0,0,.5));
}
.login-hero h1 {
  font-size: clamp(35px, 5vw, 74px);
  line-height: .98;
  letter-spacing: -.06em;
  margin: 22px 0 0;
}
.login-hero p { color: #aaa; text-align: center; margin: 10px 0 0; font-size: clamp(14px, 1.35vw, 19px); }
.login-panel { background: #fff; display: grid; place-items: center; padding: 30px; }
.login-form { width: min(420px, 100%); display: block; }
.login-form-heading { margin-bottom: 28px; }
.login-form h2 { font-size: 32px; margin: 0 0 8px; letter-spacing: -.03em; }
.login-form-heading p { color: var(--muted); margin: 0; font-size: 15px; }
.login-field { display: grid; gap: 6px; margin-bottom: 13px; }
.login-field > label { font-size: 12px; font-weight: 750; color: #555; }
.login-field input { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 13px; min-height: 46px; outline: none; }
.login-field input:focus { border-color: #111; box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 82px; }
.password-toggle { position: absolute; right: 7px; top: 7px; border: 0; border-radius: 8px; padding: 8px 10px; background: var(--surface-2); color: var(--ink); font-size: 12px; font-weight: 800; }
.login-submit { min-height: 44px; margin-top: 3px; }

label { display: flex; flex-direction: column; gap: 7px; font-weight: 700; font-size: 13px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; background: #fff; color: var(--ink); outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--dark); box-shadow: 0 0 0 3px rgba(17,17,17,.09); }
textarea { min-height: 88px; resize: vertical; }
input[readonly] { background: var(--surface-2); color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
.form-message { min-height: 22px; color: var(--danger); margin: 14px 0 0; }

.btn { border: 1px solid transparent; border-radius: 11px; padding: 10px 14px; font-weight: 800; transition: transform .12s, background .12s, border-color .12s; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--dark); color: #fff; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-soft { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: #fff2f2; color: var(--danger); border-color: #efc7c7; }
.btn-success { background: #edf8f1; color: var(--success); border-color: #c6e5d1; }
.btn-ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.18); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 10px; border-radius: 9px; font-size: 12px; }
.icon-btn { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 21px; display: grid; place-items: center; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--dark); color: #fff; padding: 22px 14px 16px; display: flex; flex-direction: column; z-index: 20; }
.sidebar-brand { padding: 0 9px 22px; }
.sidebar-logo { width: 54px; height: 54px; flex: 0 0 auto; object-fit: contain; border-radius: 50%; background: #fff; }
.sidebar-brand .brand-copy small { color: #aaa; }
.main-nav { display: flex; flex-direction: column; gap: 5px; overflow: auto; }
.nav-item { border: 0; background: transparent; color: #c7c7c7; padding: 11px 13px; border-radius: 11px; display: flex; align-items: center; gap: 12px; text-align: left; font-weight: 750; }
.nav-item:hover, .nav-item.active { background: #2b2b2b; color: #fff; }
.sidebar-footer { margin-top: auto; padding-top: 18px; }
.user-chip { padding: 10px 6px 14px; font-size: 12px; color: #cfcfcf; }
.user-chip strong { display: block; color: #fff; font-size: 14px; margin-bottom: 2px; }
.app-main { min-width: 0; }
.topbar { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 26px; border-bottom: 1px solid var(--line); background: rgba(245,245,243,.92); position: sticky; top: 0; z-index: 15; backdrop-filter: blur(12px); }
.topbar h2 { margin: 0; font-size: 24px; }
.topbar p { margin: 3px 0 0; font-size: 13px; }
.date-badge { display: inline-flex; background: var(--surface); border: 1px solid var(--line); padding: 8px 12px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.content { padding: 24px 26px 50px; max-width: 1600px; margin: 0 auto; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 8px 24px rgba(0,0,0,.035); }
.card h3 { margin: 0 0 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; }
.card-head h3, .card-head p { margin: 0; }
.stat-card { min-height: 128px; display: flex; flex-direction: column; justify-content: space-between; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
.stat-value { font-size: clamp(25px, 3vw, 38px); font-weight: 900; letter-spacing: -.04em; }
.stat-foot { color: var(--muted); font-size: 12px; }
.section-title { margin: 0 0 16px; }
.toolbar { display: flex; align-items: end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar-group { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.toolbar label { min-width: 155px; }
.search-box { min-width: min(340px, 100%); }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; background: #f4f4f1; color: #4c4c49; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
tbody tr:hover { background: #fafaf8; }
tbody tr:last-child td { border-bottom: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; background: var(--surface-2); font-size: 11px; font-weight: 800; }
.badge.success { background: #edf8f1; color: var(--success); }
.badge.danger { background: #fff1f1; color: var(--danger); }
.badge.dark { background: var(--dark); color: #fff; }
.empty-state { text-align: center; padding: 36px 18px; color: var(--muted); }

.billing-layout { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(340px,.7fr); gap: 18px; align-items: start; }
.sticky-card { position: sticky; top: 106px; }
.search-results { border: 1px solid var(--line); border-radius: 11px; background: #fff; max-height: 280px; overflow: auto; margin-top: 7px; }
.search-result { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 11px 12px; text-align: left; display: flex; justify-content: space-between; gap: 12px; }
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: #f5f5f2; }
.search-result strong { display: block; }
.search-result small { color: var(--muted); }
.customer-selected { border: 1px solid var(--dark); border-radius: 12px; padding: 14px; background: #fafaf8; }
.customer-selected h4 { margin: 0 0 8px; }
.cart-table input { width: 86px; padding: 7px 8px; }
.cart-summary { display: grid; gap: 8px; margin-top: 16px; }
.cart-summary .line { display: flex; justify-content: space-between; gap: 20px; }
.cart-summary .total { font-size: 23px; font-weight: 900; padding-top: 10px; border-top: 2px solid var(--dark); }
.auto-date { padding: 12px 14px; border-radius: 11px; background: #f1f1ed; border: 1px solid var(--line); font-weight: 800; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 20px; z-index: 100; }
.modal { width: min(900px, 100%); max-height: 92vh; overflow: hidden; background: #fff; border-radius: 18px; box-shadow: 0 24px 80px rgba(0,0,0,.25); display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { overflow: auto; padding: 18px; }
.toast-region { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { width: min(380px, calc(100vw - 36px)); background: #111; color: #fff; border-radius: 12px; padding: 13px 15px; box-shadow: var(--shadow); animation: toastIn .18s ease-out; }
.toast.error { background: #811d1d; }
.toast.success { background: #145c32; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

.chart-bars { display: flex; align-items: end; gap: 8px; min-height: 180px; overflow-x: auto; padding: 8px 4px 0; }
.chart-bar-wrap { min-width: 42px; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chart-bar { width: 100%; min-height: 3px; background: #222; border-radius: 7px 7px 2px 2px; }
.chart-bar-wrap small { color: var(--muted); font-size: 10px; }


.print-root { display: none; }
.invoice-sheet {
  background: #fff;
  color: #000;
  width: 5.5in;
  height: 8.5in;
  min-height: 8.5in;
  padding: .22in .24in .18in;
  font-family: "Times New Roman", Times, serif;
  font-size: 9.7px;
  line-height: 1.18;
  display: block;
  position: relative;
  padding-bottom: .42in;
  overflow: hidden;
}
.invoice-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 10px;
  align-items: start;
  padding-bottom: 6px;
  border-bottom: 1px solid #000;
}
.invoice-company { text-align: center; padding-left: 66px; }
.invoice-company h1 { font-size: 14px; letter-spacing: .02em; margin: 0 0 2px; }
.invoice-company p { margin: 1px 0; }
.invoice-document { text-align: right; }
.invoice-logo-img { width: 47px; height: 47px; display: block; margin: 0 0 4px auto; object-fit: contain; }
.invoice-document p { margin: 1px 0; white-space: nowrap; }
.invoice-meta {
  display: grid;
  grid-template-columns: 1.18fr .82fr;
  gap: 12px;
  border-bottom: 1px solid #000;
  padding: 5px 0;
}
.invoice-meta p { margin: 1px 0; overflow-wrap: anywhere; }
.invoice-meta strong { display: inline-block; min-width: 67px; }
.invoice-items { width: 100%; min-width: 0; margin-top: 5px; border: 1px solid #000; table-layout: fixed; }
.invoice-items th, .invoice-items td { border: 1px solid #000; padding: 3px 3px; font-size: 9px; line-height: 1.12; }
.invoice-items th { background: #fff; color: #000; position: static; text-align: center; font-weight: 700; }
.invoice-items td { vertical-align: top; }
.invoice-items .col-code { width: 13%; }
.invoice-items .col-desc { width: 43%; }
.invoice-items .col-qty { width: 11%; }
.invoice-items .col-unit { width: 16%; }
.invoice-items .col-total { width: 17%; }
.invoice-notes-total { display: grid; grid-template-columns: 1fr 1.35in; border: 1px solid #000; border-top: 0; min-height: .95in; }
.invoice-notes { padding: 4px; border-right: 1px solid #000; overflow-wrap: anywhere; }
.invoice-grand-total { display: flex; align-items: flex-end; justify-content: space-between; gap: 5px; padding: 5px; font-size: 12px; font-weight: 900; }
.invoice-continuation { border: 1px solid #000; border-top: 0; padding: 5px; text-align: right; font-style: italic; }
.invoice-footer { position: absolute; left: .24in; right: .24in; bottom: .18in; display: grid; grid-template-columns: 1fr auto; gap: 10px; border-top: 1px solid #000; padding-top: 3px; font-size: 8.5px; }
.plan-sheet { width: 8.5in; min-height: 11in; background: #fff; color: #000; padding: .35in; font-family: Arial, sans-serif; font-size: 11px; }
.plan-sheet h1 { text-align: center; font-size: 18px; margin: 0 0 5px; }
.plan-sheet .plan-meta { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 12px; }
.plan-sheet table { min-width: 0; border: 1px solid #000; }
.plan-sheet th, .plan-sheet td { border: 1px solid #000; padding: 5px; }
.plan-sheet th { position: static; background: #eee; color: #000; }

@media (min-width: 761px) and (max-width: 1050px) {
  .login-screen { grid-template-columns: .95fr 1.05fr; }
  .login-hero { padding: 36px 24px; }
  .login-logo { width: min(300px, 73%); }
  .login-hero h1 { font-size: clamp(34px, 5vw, 52px); }
  .app-shell { grid-template-columns: 215px minmax(0, 1fr); }
  .sidebar { padding-inline: 11px; }
  .sidebar-logo { width: 46px; height: 46px; }
  .sidebar-brand .brand-copy strong { font-size: 12px; }
  .content { padding-inline: 18px; }
}
@media (max-width: 1050px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .billing-layout { grid-template-columns: 1fr; }
  .sticky-card { position: static; }
}
@media (max-width: 760px) {
  .mobile-only { display: grid; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: -270px; width: 245px; transition: left .18s ease-out; box-shadow: 20px 0 50px rgba(0,0,0,.2); }
  .sidebar.open { left: 0; }
  .topbar { padding: 12px 14px; min-height: 70px; justify-content: flex-start; }
  .topbar-actions { margin-left: auto; }
  .date-badge { display: none; }
  .content { padding: 16px 12px 40px; }
  .grid-2, .grid-3, .grid-4, .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-grid .span-3 { grid-column: auto; }
  .card { padding: 14px; border-radius: 13px; }
  .toolbar, .toolbar-group { align-items: stretch; flex-direction: column; width: 100%; }
  .toolbar label, .search-box { min-width: 0; width: 100%; }
  .toolbar .btn { width: 100%; }
  .login-screen { display: block; min-height: 100vh; background: #fff; }
  .login-hero { min-height: 270px; padding: 25px; }
  .login-logo { width: 150px; height: 150px; }
  .login-hero h1 { margin-top: 12px; font-size: 34px; }
  .login-hero p { margin: 7px 0 0; font-size: 13px; }
  .login-panel { padding: 25px 18px 36px; place-items: start center; }
  .login-form h2 { font-size: 25px; }
  .login-field input { min-height: 48px; font-size: 16px; }
  .modal-backdrop { padding: 8px; }
  .modal { max-height: 97vh; border-radius: 13px; }
}


@media (max-width: 420px) {
  .login-hero { min-height: 245px; }
  .login-logo { width: 132px; height: 132px; }
  .login-hero h1 { font-size: 30px; }
  .login-panel { padding-inline: 15px; }
  .topbar h2 { font-size: 20px; }
  .content { padding-inline: 10px; }
  .card { padding: 12px; }
}

@media print {
  @page { size: 5.5in 8.5in; margin: 0; }
  html, body { background: #fff !important; }
  body > *:not(#printRoot) { display: none !important; }
  #printRoot { display: block !important; }
  .invoice-sheet { break-after: page; page-break-after: always; }
  .invoice-sheet:last-child { break-after: auto; page-break-after: auto; }
  body.printing-plan .plan-sheet { display: block; }
  body.printing-plan .invoice-sheet { display: none; }
  body.printing-plan { --unused: 0; }
}
