:root {
  --bg: #FDFBF7;
  --surface: #FFFFFF;
  --surface-2: #F7F3EC;
  --primary: #1B4332;
  --active: #2D6A4F;
  --soft: #E9F2EC;
  --text: #1A1D20;
  --muted: #6C757D;
  --border: #EAE6DF;
  --sand: #D9CDBC;
  --danger: #C93C3C;
  --danger-soft: #FFF4F3;
  --warning: #9A6700;
  --warning-soft: #FFF8E6;
  --success: #237A46;
  --shadow: 0 16px 45px rgba(27, 67, 50, .08);
  --sidebar: 248px;
  --radius: 18px;
  --font-scale: 1;
}

html[data-theme="dark"] {
  --bg: #101713;
  --surface: #1A261F;
  --surface-2: #142019;
  --primary: #F2F7F3;
  --active: #70C38E;
  --soft: #203B2B;
  --text: #FDFBF7;
  --muted: #B8AD9A;
  --border: #39483F;
  --sand: #5A5146;
  --danger: #FF817A;
  --danger-soft: #3B201F;
  --warning: #FFD36A;
  --warning-soft: #332B17;
  --success: #70C38E;
  --shadow: 0 16px 45px rgba(0,0,0,.22);
}

html[data-larger-text="true"] { --font-scale: 1.12; }
html { font-size: calc(16px * var(--font-scale)); }
html[data-reduce-motion="true"] *,
html[data-reduce-motion="true"] *::before,
html[data-reduce-motion="true"] *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  scroll-behavior: auto !important;
  transition-duration: .001ms !important;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--active); }
button { cursor: pointer; }
.skip-link {
  position: fixed; z-index: 1000; left: 1rem; top: -5rem;
  background: var(--primary); color: var(--surface); padding: .7rem 1rem;
  border-radius: 10px; text-decoration: none;
}
.skip-link:focus { top: 1rem; }

.boot-screen {
  min-height: 100vh; display: grid; place-items: center; align-content: center;
  gap: .6rem; color: var(--primary);
}
.boot-logo { width: 74px; height: 74px; border-radius: 20px; box-shadow: var(--shadow); }
.boot-screen strong { font: 700 2rem Georgia, serif; }
.boot-screen span { color: var(--muted); }
.noscript-card { margin: 2rem; padding: 1rem; border: 1px solid var(--border); background: var(--surface); border-radius: 14px; }

/* Auth */
.auth-shell {
  min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  background: var(--bg);
}
.auth-visual {
  position: relative; overflow: hidden; padding: clamp(2rem, 6vw, 6rem);
  display: flex; flex-direction: column; justify-content: center;
  background:
    radial-gradient(circle at 18% 10%, rgba(64,145,108,.18), transparent 30rem),
    radial-gradient(circle at 86% 88%, rgba(217,205,188,.35), transparent 26rem),
    var(--bg);
}
.auth-brand { display: inline-flex; align-items: center; gap: .8rem; color: var(--primary); font: 700 1.45rem Georgia, serif; text-decoration: none; }
.auth-brand img { width: 50px; height: 50px; border-radius: 14px; }
.auth-visual h1 { margin: 2.2rem 0 1rem; max-width: 720px; color: var(--primary); font: 700 clamp(2.6rem, 5.5vw, 5.4rem)/1.02 Georgia, serif; letter-spacing: -.04em; }
.auth-visual p { max-width: 620px; color: var(--muted); font-size: 1.08rem; line-height: 1.7; }
.auth-feature-row { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.8rem; }
.auth-pill { padding: .65rem .85rem; border: 1px solid var(--border); border-radius: 999px; background: color-mix(in srgb, var(--surface) 78%, transparent); color: var(--primary); font-weight: 700; font-size: .9rem; }
.auth-panel { min-height: 100vh; display: flex; align-items: center; padding: 2rem; border-left: 1px solid var(--border); background: var(--surface); }
.auth-card { width: 100%; max-width: 420px; margin: auto; }
.auth-card h2 { margin: 0; color: var(--primary); font: 700 2rem Georgia, serif; }
.auth-card > p { color: var(--muted); line-height: 1.6; margin: .7rem 0 1.6rem; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; background: var(--surface-2); border-radius: 13px; margin-bottom: 1.35rem; }
.auth-tab { border: 0; border-radius: 10px; padding: .7rem; background: transparent; color: var(--muted); font-weight: 750; }
.auth-tab.active { background: var(--surface); color: var(--primary); box-shadow: 0 3px 12px rgba(0,0,0,.06); }
.form-grid { display: grid; gap: 1rem; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.field { display: grid; gap: .38rem; }
.field label { font-size: .88rem; font-weight: 750; color: var(--primary); }
.field small { color: var(--muted); }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: .78rem .88rem;
  background: var(--surface); color: var(--text); outline: 0;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--active); box-shadow: 0 0 0 3px color-mix(in srgb, var(--active) 18%, transparent); }
.textarea { min-height: 100px; resize: vertical; }
.auth-actions { display: grid; gap: .75rem; margin-top: 1.15rem; }
.btn {
  border: 1px solid transparent; border-radius: 12px; min-height: 44px; padding: .7rem 1rem;
  display: inline-flex; justify-content: center; align-items: center; gap: .48rem;
  background: var(--primary); color: var(--surface); font-weight: 800; text-decoration: none;
}
.btn:hover { filter: brightness(.96); }
.btn.secondary { background: var(--surface); color: var(--primary); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--primary); border-color: transparent; }
.btn.danger { background: var(--danger); color: white; }
.btn.small { min-height: 36px; padding: .48rem .68rem; border-radius: 10px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .8rem; text-transform: uppercase; font-weight: 800; letter-spacing: .08em; margin: 1.25rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.notice { border: 1px solid var(--border); border-radius: 12px; padding: .85rem 1rem; background: var(--surface-2); color: var(--muted); font-size: .9rem; line-height: 1.5; }
.notice.warning { border-color: color-mix(in srgb, var(--warning) 30%, var(--border)); background: var(--warning-soft); color: var(--text); }
.notice.success { border-color: color-mix(in srgb, var(--success) 30%, var(--border)); background: color-mix(in srgb, var(--success) 10%, var(--surface)); color: var(--text); }
.notice.error { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); background: var(--danger-soft); color: var(--text); }
.link-button { border: 0; padding: 0; background: none; color: var(--active); font-weight: 750; }
.auth-footer { margin-top: 1.25rem; display: flex; flex-wrap: wrap; gap: 1rem; font-size: .85rem; }

/* App shell */
.workspace { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid var(--border);
  background: var(--surface); padding: 1.1rem .85rem; display: flex; flex-direction: column;
}
.sidebar-brand { display: flex; align-items: center; gap: .7rem; padding: .35rem .45rem 1rem; text-decoration: none; color: var(--primary); }
.sidebar-brand img { width: 42px; height: 42px; border-radius: 12px; }
.sidebar-brand strong { font: 700 1.28rem Georgia, serif; }
.business-switcher { margin: .25rem .35rem 1rem; padding: .75rem; border-radius: 13px; background: var(--surface-2); border: 1px solid var(--border); }
.business-switcher small { display: block; color: var(--muted); font-size: .73rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 800; }
.business-switcher strong { display: block; margin-top: .15rem; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-nav { display: grid; gap: .25rem; }
.nav-item {
  width: 100%; min-height: 43px; border: 0; border-radius: 11px; background: transparent; color: var(--text);
  display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: .65rem; padding: .62rem .72rem;
  text-align: left; font-weight: 700;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--soft); color: var(--primary); }
.nav-icon { width: 23px; text-align: center; font-size: 1.05rem; }
.nav-badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: grid; place-items: center; background: var(--danger); color: white; font-size: .72rem; }
.sidebar-bottom { margin-top: auto; padding-top: 1rem; display: grid; gap: .35rem; border-top: 1px solid var(--border); }
.web-mode { margin: .3rem; font-size: .75rem; color: var(--muted); line-height: 1.4; }

.main-area { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; min-height: 70px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(16px);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem clamp(1rem, 3vw, 2rem);
}
.mobile-menu { display: none; }
.topbar-title { min-width: 0; }
.topbar-title strong { display: block; color: var(--primary); font: 700 1.32rem Georgia, serif; }
.topbar-title span { color: var(--muted); font-size: .85rem; }
.topbar-actions { display: flex; align-items: center; gap: .6rem; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--primary); }
.avatar { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--primary); color: var(--surface); font-weight: 850; }
.content { width: min(100%, 1320px); margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.35rem; }
.page-head h1 { margin: 0; color: var(--primary); font: 700 clamp(1.8rem, 4vw, 2.7rem)/1.05 Georgia, serif; letter-spacing: -.025em; }
.page-head p { margin: .45rem 0 0; color: var(--muted); max-width: 720px; }
.page-actions { display: flex; flex-wrap: wrap; gap: .65rem; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.stat-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.05rem; background: var(--surface); box-shadow: var(--shadow); }
.stat-card span { color: var(--muted); font-size: .84rem; font-weight: 700; }
.stat-card strong { display: block; margin-top: .4rem; color: var(--primary); font: 700 2rem Georgia, serif; }
.stat-foot { margin-top: .35rem; color: var(--muted); font-size: .78rem; }

.dashboard-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 1rem; margin-top: 1rem; }
.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: 1rem 1.05rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: .8rem; }
.panel-head h2 { margin: 0; color: var(--primary); font: 700 1.2rem Georgia, serif; }
.panel-body { padding: 1rem 1.05rem; }
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.quick-card { border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); padding: .95rem; text-align: left; color: var(--text); }
.quick-card strong { display: block; color: var(--primary); margin: .4rem 0 .25rem; }
.quick-card span { color: var(--muted); font-size: .82rem; }

.list { display: grid; gap: .7rem; }
.list-item { border: 1px solid var(--border); border-radius: 14px; padding: .9rem; background: var(--surface); display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.item-main { min-width: 0; }
.item-main strong { color: var(--primary); }
.item-main p { margin: .25rem 0 0; color: var(--muted); font-size: .88rem; line-height: 1.45; }
.item-meta { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .55rem; color: var(--muted); font-size: .78rem; }
.item-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .4rem; }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: .2rem .55rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); font-size: .74rem; font-weight: 800; text-transform: capitalize; }
.badge.pending { background: var(--warning-soft); color: var(--warning); }
.badge.accepted, .badge.confirmed, .badge.completed, .badge.scheduled, .badge.active { background: var(--soft); color: var(--active); }
.badge.declined, .badge.cancelled, .badge.refunded, .badge.archived { background: var(--danger-soft); color: var(--danger); }
.empty { text-align: center; padding: 2.6rem 1rem; color: var(--muted); }
.empty strong { display: block; margin-bottom: .35rem; color: var(--primary); font: 700 1.2rem Georgia, serif; }

.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.search-box { flex: 1; min-width: 220px; max-width: 500px; }
.segmented { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button { border: 0; border-radius: 8px; padding: .48rem .72rem; background: transparent; color: var(--muted); font-weight: 750; }
.segmented button.active { background: var(--surface); color: var(--primary); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: .78rem .85rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); background: var(--surface-2); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; }
td { font-size: .9rem; }
tr:last-child td { border-bottom: 0; }
.cell-title { color: var(--primary); font-weight: 800; }
.cell-sub { color: var(--muted); font-size: .78rem; margin-top: .15rem; }

.schedule-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.sale-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.product-card { border: 1px solid var(--border); border-radius: 15px; padding: .9rem; background: var(--surface); }
.product-card.low { border-color: color-mix(in srgb, var(--warning) 35%, var(--border)); background: var(--warning-soft); }
.product-top { display: flex; justify-content: space-between; gap: .8rem; }
.product-name { color: var(--primary); font-weight: 850; }
.product-price { font-weight: 800; }
.product-stock { margin-top: .75rem; display: flex; justify-content: space-between; color: var(--muted); font-size: .82rem; }

.settings-grid { display: grid; grid-template-columns: .8fr 1.2fr; gap: 1rem; }
.profile-card { text-align: center; padding: 1.3rem; }
.profile-avatar { width: 74px; height: 74px; margin: 0 auto .8rem; border-radius: 20px; display: grid; place-items: center; background: var(--primary); color: var(--surface); font: 800 1.5rem Georgia, serif; }
.settings-list { display: grid; gap: .7rem; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); }
.setting-row strong { display: block; color: var(--primary); }
.setting-row span { color: var(--muted); font-size: .82rem; }
.switch { position: relative; width: 48px; height: 28px; border-radius: 999px; background: var(--border); border: 0; flex: 0 0 auto; }
.switch::after { content: ""; position: absolute; width: 22px; height: 22px; top: 3px; left: 3px; border-radius: 50%; background: white; box-shadow: 0 1px 5px rgba(0,0,0,.18); transition: transform .18s ease; }
.switch.on { background: var(--active); }
.switch.on::after { transform: translateX(20px); }

/* Modal / toast */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1rem; background: rgba(6, 15, 10, .52); }
.modal { width: min(100%, 620px); max-height: min(90vh, 820px); overflow-y: auto; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: 0 30px 90px rgba(0,0,0,.28); }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.modal-head h2 { margin: 0; color: var(--primary); font: 700 1.35rem Georgia, serif; }
.modal-body { padding: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .65rem; margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.close-btn { width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--primary); }
.toast-stack { position: fixed; z-index: 200; right: 1rem; bottom: 1rem; display: grid; gap: .6rem; width: min(380px, calc(100vw - 2rem)); }
.toast { border: 1px solid var(--border); border-radius: 13px; padding: .82rem .9rem; background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
.toast.error { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.toast.success { border-color: color-mix(in srgb, var(--success) 35%, var(--border)); }
.loading-line { height: 4px; background: linear-gradient(90deg, transparent, var(--active), transparent); background-size: 200% 100%; animation: loading 1.1s infinite linear; }
@keyframes loading { to { background-position: -200% 0; } }

.mobile-overlay { display: none; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-visual { min-height: 38vh; padding: 2rem; }
  .auth-visual h1 { font-size: clamp(2.2rem, 9vw, 3.6rem); margin-top: 1.4rem; }
  .auth-panel { min-height: auto; border-left: 0; border-top: 1px solid var(--border); padding: 1.5rem; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 80; width: min(84vw, 290px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 20px 0 60px rgba(0,0,0,.18); }
  .sidebar.open { transform: translateX(0); }
  .mobile-overlay { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.35); display: none; }
  .mobile-overlay.open { display: block; }
  .mobile-menu { display: grid; }
  .schedule-columns, .sale-grid { grid-template-columns: 1fr; }
  .topbar { padding-inline: 1rem; }
}
@media (max-width: 600px) {
  .content { padding: 1rem; }
  .page-head { display: grid; }
  .page-actions .btn { flex: 1; }
  .stat-grid, .product-grid, .form-grid.two { grid-template-columns: 1fr; }
  .quick-grid { grid-template-columns: 1fr; }
  .list-item { display: grid; }
  .item-actions { justify-content: flex-start; }
  .topbar-title span { display: none; }
  .auth-feature-row { display: none; }
}
