:root {
  --green: #0f6b3f;
  --green-dark: #0a4d2c;
  --green-light: #1a8a55;
  --gold: #c9a227;
  --gold-light: #e3c45c;
  --bg: #f6f9f7;
  --surface: #ffffff;
  --text: #1c2b22;
  --muted: #6b7d72;
  --border: #e3eae5;
  --danger: #c0392b;
  --success: #1a8a55;
  --shadow: 0 4px 18px rgba(15, 107, 63, 0.08);
  --radius: 14px;
}
[data-theme="dark"] {
  --bg: #0d1411;
  --surface: #16201b;
  --text: #e8f0ea;
  --muted: #8fa89a;
  --border: #243029;
  --shadow: 0 4px 18px rgba(0,0,0,0.4);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .3s, color .3s;
}
a { color: var(--green); text-decoration: none; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: none; border-radius: 10px; padding: 9px 16px; font-size: 14px; font-weight: 600;
  background: var(--green); color: #fff; transition: transform .15s, box-shadow .2s, background .2s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(15,107,63,.25); }
.btn.gold { background: var(--gold); color: #1c2b22; }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font-size: 14px; transition: border .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(15,107,63,.12); }
label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 5px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 256px; background: linear-gradient(180deg, var(--green-dark), var(--green));
  color: #fff; padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  transition: width .25s, transform .25s; z-index: 40;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar .brand .logo { width: 40px; height: 40px; border-radius: 10px; background: var(--gold); display: grid; place-items: center; font-weight: 800; color: var(--green-dark); }
.sidebar .brand b { font-size: 15px; line-height: 1.1; }
.sidebar .brand small { color: var(--gold-light); font-size: 11px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; color: #e7f3ec; font-size: 14px; margin-top: 4px; transition: background .2s; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.14); color: #fff; }
.nav-item.active { border-left: 3px solid var(--gold); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 22px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
}
.topbar .menu-btn { display: none; font-size: 22px; cursor: pointer; background: none; border: none; color: var(--text); }
.topbar .title { font-size: 18px; font-weight: 700; }
.topbar .spacer { flex: 1; }
.search-box { position: relative; }
.search-box input { width: 260px; padding-left: 34px; }
.search-box .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); opacity: .5; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--text); position: relative; }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.content { padding: 22px; flex: 1; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.card {
  background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  border: 1px solid var(--border); position: relative; overflow: hidden; animation: rise .4s ease both;
}
.card::after { content:''; position:absolute; right:-20px; top:-20px; width:70px; height:70px; border-radius:50%; background: radial-gradient(circle, rgba(201,162,39,.18), transparent 70%); }
.card .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: rgba(15,107,63,.1); color: var(--green); font-size: 20px; margin-bottom: 12px; }
.card .label { color: var(--muted); font-size: 13px; }
.card .value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.card.gold .ic { background: rgba(201,162,39,.15); color: var(--gold); }

/* Panels */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 18px; margin-bottom: 20px; animation: rise .45s ease both; }
.panel h3 { font-size: 16px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.panel h3 .badge { font-size: 11px; background: var(--gold); color: #1c2b22; padding: 2px 8px; border-radius: 20px; font-weight: 700; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(15,107,63,.04); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.green { background: rgba(26,138,85,.14); color: var(--green); }
.pill.red { background: rgba(192,57,43,.14); color: var(--danger); }
.pill.gold { background: rgba(201,162,39,.16); color: var(--gold); }
.pill.gray { background: rgba(110,125,114,.15); color: var(--muted); }

.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media(max-width: 1000px) { .grid2 { grid-template-columns: 1fr; } }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media(max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

/* Login */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; background: linear-gradient(135deg, var(--green-dark), var(--green)); padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .logo { width: 64px; height: 64px; border-radius: 16px; background: var(--gold); display: grid; place-items: center; font-weight: 800; font-size: 24px; color: var(--green-dark); margin: 0 auto 14px; }
.login-card h2 { text-align: center; font-size: 20px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.pw-wrap { position: relative; }
.pw-wrap .toggle { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); cursor: pointer; background: none; border: none; color: var(--muted); }

/* Loading screen */
#loader { position: fixed; inset: 0; background: var(--green-dark); z-index: 9999; display: grid; place-items: center; transition: opacity .5s; }
#loader .moon { width: 70px; height: 70px; border-radius: 50%; border: 5px solid var(--gold); border-top-color: transparent; animation: spin 1s linear infinite; }

/* Toast */
#toasts { position: fixed; top: 18px; right: 18px; z-index: 9998; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface); border-left: 4px solid var(--green); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); min-width: 230px; animation: slideIn .3s ease; font-size: 14px; }
.toast.gold { border-left-color: var(--gold); }
.toast.danger { border-left-color: var(--danger); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 9997; display: none; place-items: center; padding: 16px; }
.modal-bg.show { display: grid; }
.modal { background: var(--surface); border-radius: 16px; padding: 24px; width: 100%; max-width: 460px; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: rise .3s ease; }
.modal h3 { margin-bottom: 12px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* Receipt */
.receipt { max-width: 720px; margin: 0 auto; background: var(--surface); border: 2px solid var(--gold); border-radius: 16px; padding: 28px; }
.receipt .head { text-align: center; border-bottom: 2px dashed var(--border); padding-bottom: 16px; margin-bottom: 16px; }
.receipt .rows { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px; }
.receipt .rows div { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--border); padding: 6px 0; }
.receipt .qr { display: grid; place-items: center; margin-top: 18px; }

/* Charts */
.chart-box { height: 240px; }

/* Misc */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }
.pagination a, .pagination span { padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; }
.pagination .active { background: var(--green); color: #fff; border-color: var(--green); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: end; }
.filters > div { flex: 1; min-width: 150px; }
.kbd { font-size: 11px; background: var(--border); padding: 2px 6px; border-radius: 5px; font-family: monospace; }

/* Animations */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@media print {
  .sidebar, .topbar, .no-print, #loader, #toasts, .modal-bg { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; }
}

/* Sidebar overlay (mobile) */
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 35; opacity: 0; visibility: hidden; transition: opacity .25s; }
.sidebar-overlay.show { opacity: 1; visibility: visible; }

/* Responsive sidebar + mobile layout */
@media(max-width: 860px) {
  .sidebar { position: fixed; top: 0; left: 0; transform: translateX(-100%); width: 250px; z-index: 40; box-shadow: 0 0 40px rgba(0,0,0,.45); }
  .sidebar.open { transform: translateX(0); }
  .topbar .menu-btn { display: block; }
  .content { padding: 12px; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .topbar .title { font-size: 15px; }
  .search-box { order: 6; flex: 1 0 100%; width: 100%; }
  .search-box input { width: 100%; }
  #searchResults { left: 0; right: 0; width: auto; }
  /* wide tables scroll horizontally instead of breaking layout */
  table { display: block; width: 100%; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .receipt .rows { grid-template-columns: 1fr; }
  .pagination { flex-wrap: wrap; }
}
@media(max-width: 480px) {
  .topbar .title { display: none; }
  .icon-btn { width: 36px; height: 36px; }
  .card .value { font-size: 22px; }
  .content { padding: 10px; }
  .btn { padding: 8px 12px; font-size: 13px; }
}
