:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e6e8ef;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --success-light: #ecfdf3;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --info: #2563eb;
  --info-light: #eff6ff;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
/* Baseline reset for every <button> — .btn/.icon-btn/etc. and the Tailwind-only overlay/menu
   buttons all fully specify their own look via classes, so this just removes the browser's
   native chrome (border, background, padding) they'd otherwise start from. */
button { font: inherit; color: inherit; background: none; border: none; padding: 0; margin: 0; cursor: pointer; appearance: none; -webkit-appearance: none; }
h1, h2, h3 { margin: 0 0 4px; font-weight: 700; }
p { margin: 0 0 8px; }
img { max-width: 100%; }
.container { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.container-narrow { max-width: 640px; }
.muted { color: var(--text-muted); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11px; }
.text-strong { font-weight: 700; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; color: var(--text); }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); flex-shrink: 0; }
.brand-accent { color: var(--primary); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600; cursor: pointer; background: none; font-family: inherit;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-danger-outline { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-light); text-decoration: none; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  border-radius: 7px; border: 1px solid var(--border); background: #fff; cursor: pointer; color: var(--text-muted);
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }
.notif-bell { position: relative; margin-left: auto; }
.notif-bell:hover { color: var(--primary); border-color: var(--primary); }
.notif-badge {
  position: absolute; top: -6px; right: -6px; min-width: 17px; height: 17px; padding: 0 3px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; line-height: 17px; text-align: center;
}

/* ---------- Forms ---------- */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 200px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-grow { flex-grow: 1; }
.field-label { font-size: 13px; font-weight: 600; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text); }
input, select, textarea {
  font: inherit; font-size: 13.5px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
input[readonly] { background: #f9fafb; color: var(--text-muted); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.inline-form { display: flex; gap: 8px; margin-top: 14px; }

/* ---------- Alerts / badges ---------- */
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; }
.alert-success { background: var(--success-light); color: #15803d; }
.alert-danger { background: var(--danger-light); color: #b91c1c; }
.alert-info { background: var(--info-light); color: #1d4ed8; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-muted { background: #f1f2f6; color: #4b5563; }
.badge-info { background: var(--info-light); color: #1d4ed8; }
.badge-success { background: var(--success-light); color: #15803d; }
.badge-danger { background: var(--danger-light); color: #b91c1c; }
.badge-neutral { background: #ede9fe; color: #6d28d9; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--border); font-size: 12.5px; margin: 4px 6px 0 0; }

/* ---------- App shell ---------- */
.demo-banner { background: #fffbeb; color: #92400e; text-align: center; padding: 8px 14px; font-size: 12.5px; }
.demo-banner a { color: #92400e; font-weight: 700; }
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: #fff; border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.app-sidebar .brand { padding: 0 8px 16px; }
.app-sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: #9ca3af; font-weight: 700; padding: 14px 10px 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #374151;
  font-size: 13.5px; font-weight: 500;
}
.nav-link:hover { background: #f3f4f6; text-decoration: none; }
.nav-link.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 700; }
.nav-link-btn { width: 100%; text-align: left; background: none; border: none; cursor: pointer; font: inherit; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 10px 4px; font-size: 12px; color: var(--text-muted); }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.app-topbar strong { font-size: 16px; }
.topbar-tenant { margin-left: auto; }
.mobile-menu-btn { display: none; }
.app-content { padding: 22px 24px 90px; flex: 1; }

.mobile-bottom-nav { display: none; }

/* ---------- Dashboard / panels ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-title { display: flex; align-items: center; gap: 8px; font-size: 20px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 { font-size: 15px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-value { font-size: 26px; font-weight: 800; color: var(--primary-dark); }
.stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.quick-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; border-radius: 10px;
  background: #fafafe; border: 1px solid var(--border); color: var(--text); font-size: 11.5px; font-weight: 600; text-align: center;
}
.quick-item:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); text-decoration: none; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid #f1f2f6; vertical-align: middle; }
.table tfoot td { border-top: 2px solid var(--border); border-bottom: none; }
.table-compact td, .table-compact th { padding: 6px 8px; }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }

/* ---------- Document list: desktop table / mobile deck ---------- */
.doc-table-wrap { overflow-x: auto; }
.doc-row { cursor: pointer; }
.doc-row:hover { background: #fafafe; }

/* Any clickable row (documents, master data, users, dashboard) that opens the detail overlay. */
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr[data-href]:hover { background: #fafafe; }
.doc-deck { display: none; }
body.overlay-open { overflow: hidden; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab { padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.tab.active { color: var(--primary); font-weight: 800; text-shadow: 0 0 12px rgba(79, 70, 229, 0.45); }
.tab:hover { text-decoration: none; color: var(--primary); }

/* Compact dropdown standing in for .tabs wherever there isn't room for every tab in one row
   (mobile in particular) — same options, same destinations, just picked from a <select>.
   app.js wraps every <select> in a .csel and copies this class onto that wrapper, so the
   display toggle below still applies once the tab-select is a real select no more. */
.tab-select { display: none; margin-bottom: 14px; }

/* ---------- Custom select (every <select> is enhanced by app.js into this) ----------
   Native <select> dropdown panels can't be restyled, so app.js hides the real <select>
   (kept in the DOM for form submission / a11y) and drives a matching button + option list. */
.csel { position: relative; display: block; width: 100%; }
/* Same "visually hidden" clipping used for screen-reader-only text — far more robust across
   browsers/devices than opacity:0 alone, which some mobile browsers still paint natively
   (options rendered inline) once the control receives focus. */
.csel-native {
  position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important;
  margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important; border: 0 !important; opacity: 0; pointer-events: none;
}
.csel-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  font: inherit; font-size: 13.5px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); cursor: pointer; text-align: left;
}
.csel-trigger:hover { border-color: var(--primary); }
.csel.csel-open .csel-trigger { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.csel-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csel-chev { flex-shrink: 0; color: var(--text-muted); transition: transform .15s ease; }
.csel.csel-open .csel-chev { transform: rotate(180deg); color: var(--primary); }
.csel-panel {
  display: none; position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(15, 23, 42, .14);
  padding: 6px; max-height: 260px; overflow-y: auto;
}
.csel.csel-open .csel-panel { display: block; }
.csel-option {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px;
  font: inherit; font-size: 13.5px; font-weight: 600; color: var(--text); text-align: left;
}
.csel-option:hover { background: #f6f7fb; }
.csel-option.is-selected { background: var(--primary-light); color: var(--primary-dark); }
.csel-dot {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid #c7d2fe; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.csel-option.is-selected .csel-dot { border-color: var(--primary); }
.csel-option.is-selected .csel-dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }

/* ---------- Detail / approvals / comments ---------- */
.detail-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; margin: 0; }
.detail-list > div { display: flex; flex-direction: column; gap: 2px; }
.detail-list dt { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.detail-list dd { margin: 0; font-size: 13.5px; }
.detail-full { grid-column: 1 / -1; }

.approval-timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.approval-step { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.approval-step.approval-approved { border-color: #bbf7d0; background: var(--success-light); }
.approval-step.approval-rejected { border-color: #fecaca; background: var(--danger-light); }
.approval-step-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.approval-action-form { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; }

.comment-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.comment-item { border-bottom: 1px solid #f1f2f6; padding-bottom: 10px; }
.comment-item p { margin: 4px 0 0; font-size: 13.5px; }

/* ---------- Line item editor ---------- */
.line-editor { display: flex; flex-direction: column; gap: 8px; }
.line-row input { min-width: 60px; }

/* ---------- Public site ---------- */
.site-header { background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.site-header-inner { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; }
.site-nav { display: flex; align-items: center; gap: 22px; font-weight: 600; font-size: 13.5px; }
.hero { padding: 80px 0 60px; background: radial-gradient(circle at 20% 0%, var(--primary-light), transparent 55%); }
.hero-inner { max-width: 760px; }
.eyebrow { display: inline-block; background: var(--primary-light); color: var(--primary-dark); padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; margin-bottom: 16px; }
.hero h1 { font-size: 40px; line-height: 1.15; margin-bottom: 14px; }
.hero-sub { font-size: 16px; color: var(--text-muted); max-width: 620px; margin-bottom: 26px; }
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; }
.section { padding: 56px 0; }
.section-alt { background: #fafafe; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.section-title { font-size: 24px; margin-bottom: 24px; }
.feature-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.feature-icon { width: 44px; height: 44px; border-radius: 10px; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.doctype-chips { margin-top: 24px; }
.tenant-grid { margin-top: 8px; }
.tenant-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-align: center; box-shadow: var(--shadow); }
.tenant-avatar { width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; margin: 0 auto 10px; font-size: 18px; }
.site-footer { padding: 30px 0 60px; text-align: center; }
.site-footer .brand { justify-content: center; margin-bottom: 6px; }

/* ---------- Auth ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 24px; }
.auth-card { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 32px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.auth-brand { display: block; margin-bottom: 22px; }
.auth-card h1 { font-size: 20px; }
.auth-foot { text-align: center; margin-top: 16px; }

/* ---------- Print ---------- */
.print-head { display: flex; justify-content: space-between; gap: 20px; }
.print-signatures { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 40px; }
.print-sign-box { width: 150px; text-align: center; }
.print-sign-line { height: 50px; border-bottom: 1px solid #999; margin: 4px 0; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .hero h1 { font-size: 30px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .site-nav a:not(.btn) { display: none; }

  .mobile-menu-btn { display: inline-flex; }
  .app-sidebar { display: none; }

  .app-content { padding: 16px 14px 90px; }
  .app-topbar { padding: 12px 14px; }
  .topbar-tenant { display: none; }

  .tabs { display: none; }
  .tab-select { display: block; }

  .mobile-bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; justify-content: space-around;
  }
  .mobile-bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--text-muted); font-weight: 600; padding: 4px 6px; }
  .mobile-bottom-nav a.active { color: var(--primary); }
  .mobile-bottom-nav a.fab {
    background: var(--primary); color: #fff; width: 46px; height: 46px; border-radius: 50%; align-items: center;
    justify-content: center; margin-top: -22px; box-shadow: 0 4px 10px rgba(79,70,229,.4);
  }

  .detail-list { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }

  .doc-table-wrap { display: none; }
  .doc-deck { display: flex; flex-direction: column; }
  .doc-card {
    display: grid; grid-template-columns: 1fr auto; column-gap: 12px; row-gap: 3px;
    padding: 13px 4px; border-bottom: 1px solid #f1f2f6; cursor: pointer;
  }
  .doc-card:active { background: #fafafe; }
  .doc-card-primary { font-weight: 700; font-size: 13.5px; color: var(--text); }
  .doc-card-secondary { font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .doc-card-value { text-align: right; align-self: start; }
  .doc-card-meta { text-align: right; font-size: 12px; color: var(--text-muted); align-self: start; white-space: nowrap; }
  .doc-list-panel { padding: 4px 14px; }
}

@media print {
  .no-print { display: none !important; }
}
