/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0f1e;
  --surface: #111827;
  --surface2: #1a2235;
  --border: #1e293b;
  --accent: #38bdf8;
  --accent2: #818cf8;
  --green: #34d399;
  --orange: #fb923c;
  --red: #f87171;
  --purple: #c084fc;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font-display: 'Syne', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 14px; overflow: hidden; }

/* ===== LAYOUT ===== */
#app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: var(--topbar-h) 1fr; height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  grid-row: 1 / 3;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 0;
  transition: transform 0.3s ease;
  z-index: 100;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-weight: 800; font-size: 16px;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.brand-icon { font-size: 22px; }
.nav-links { list-style: none; padding: 12px 0; flex: 1; }
.nav-links li { margin: 2px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  text-decoration: none; color: var(--text2);
  font-size: 13.5px; font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(56,189,248,0.12); color: var(--accent); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }
.version-badge { font-size: 11px; color: var(--text3); font-family: var(--font-mono); }

/* ===== TOPBAR ===== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
}
.menu-btn { display: none; background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.page-title { font-family: var(--font-display); font-size: 16px; font-weight: 700; color: var(--text); flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.date-display { font-family: var(--font-mono); font-size: 12px; color: var(--text3); }

/* ===== MAIN ===== */
.main-content {
  overflow-y: auto; padding: 24px;
  background: var(--bg);
}

/* ===== PAGES ===== */
.page { display: none; animation: fadeIn 0.2s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== SECTION HEADER ===== */
.section-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px;
}
.section-header h1 { font-family: var(--font-display); font-size: 22px; font-weight: 800; color: var(--text); }
.subtitle { color: var(--text3); font-size: 13px; margin-top: 2px; }

/* ===== KPI CARDS ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 20px; }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative; overflow: hidden;
}
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.kpi-green::before { background: var(--green); }
.kpi-blue::before { background: var(--accent); }
.kpi-orange::before { background: var(--orange); }
.kpi-purple::before { background: var(--purple); }
.kpi-red::before { background: var(--red); }
.kpi-label { font-size: 12px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.kpi-value { font-family: var(--font-display); font-size: 22px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.kpi-sub { font-size: 11px; color: var(--text3); }

/* ===== DASH GRID ===== */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }

/* ===== CARDS ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-family: var(--font-display); font-size: 14px; font-weight: 700; }
.alert-header { background: rgba(251,146,60,0.08); }
.btn-link { background: none; border: none; color: var(--accent); font-size: 12px; cursor: pointer; font-family: var(--font-body); }
.btn-link:hover { opacity: 0.7; }

/* ===== LIST ITEMS ===== */
.list-empty { padding: 24px; text-align: center; color: var(--text3); font-size: 13px; }
.list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.list-item:last-child { border-bottom: none; }
.list-item-name { font-weight: 500; color: var(--text); }
.list-item-sub { color: var(--text3); font-size: 11px; }
.list-item-val { font-family: var(--font-mono); font-size: 13px; color: var(--green); font-weight: 500; }

/* ===== TABLES ===== */
.table-wrapper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead { background: var(--surface2); }
.data-table th { padding: 11px 14px; text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text3); }
.data-table td { padding: 11px 14px; border-top: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.table-empty { padding: 32px; text-align: center; color: var(--text3); font-size: 13px; }

/* ===== BADGES ===== */
.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green { background: rgba(52,211,153,0.15); color: var(--green); }
.badge-orange { background: rgba(251,146,60,0.15); color: var(--orange); }
.badge-red { background: rgba(248,113,113,0.15); color: var(--red); }
.badge-blue { background: rgba(56,189,248,0.15); color: var(--accent); }

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--accent); color: #0a0f1e;
  border: none; border-radius: 8px; padding: 9px 18px;
  font-family: var(--font-body); font-weight: 600; font-size: 13px;
  cursor: pointer; transition: all 0.15s;
}
.btn-primary:hover { opacity: 0.85; transform: translateY(-1px); }
.btn-secondary {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 18px;
  font-family: var(--font-body); font-size: 13px; cursor: pointer;
}
.btn-danger {
  background: rgba(248,113,113,0.15); color: var(--red);
  border: 1px solid rgba(248,113,113,0.3); border-radius: 8px; padding: 9px 18px;
  font-family: var(--font-body); font-weight: 600; font-size: 13px; cursor: pointer;
}
.btn-group { display: flex; gap: 10px; }
.btn-icon {
  background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 5px;
  font-size: 14px; color: var(--text2); transition: all 0.15s;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon.del:hover { color: var(--red); }

/* ===== FORMS ===== */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 12px; color: var(--text2); font-weight: 500; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-input {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; color: var(--text);
  font-family: var(--font-body); font-size: 13px; width: 100%;
  transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-input option { background: var(--surface2); }

/* ===== SEARCH & FILTER ===== */
.search-bar { margin-bottom: 14px; }
.search-input { width: 100%; max-width: 320px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 14px; color: var(--text); font-size: 13px; }
.search-input:focus { outline: none; border-color: var(--accent); }
.filter-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.filter-select { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; color: var(--text); font-size: 13px; cursor: pointer; }
.filter-total { font-size: 13px; color: var(--text2); }
.filter-total strong { color: var(--green); font-family: var(--font-mono); }

/* ===== SALE TOTAL PREVIEW ===== */
.sale-total-preview {
  background: var(--surface2); border-radius: 8px; padding: 12px;
  text-align: center; font-size: 14px; color: var(--text2);
}
.sale-total-preview strong { font-family: var(--font-mono); font-size: 18px; color: var(--green); }

/* ===== PERIOD TABS ===== */
.period-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.period-tab {
  padding: 8px 20px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text2); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.period-tab.active { background: var(--accent); color: #0a0f1e; border-color: var(--accent); font-weight: 700; }
.period-selector { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.period-selector label { font-size: 13px; color: var(--text2); }

/* ===== CHART ===== */
canvas { display: block; width: 100% !important; padding: 16px; }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  display: none; align-items: center; justify-content: center; z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; width: 100%; max-width: 480px; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-family: var(--font-display); font-size: 16px; font-weight: 800; }
.modal-close { background: none; border: none; color: var(--text3); font-size: 18px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { color: var(--text); background: var(--surface2); }
.modal-body { padding: 20px 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 20px;
  font-size: 13px; font-weight: 500; color: var(--text);
  box-shadow: var(--shadow); z-index: 9999;
  transform: translateY(100px); opacity: 0;
  transition: all 0.3s ease; max-width: 300px;
}
.toast.show { transform: none; opacity: 1; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
    transform: translateX(-100%); z-index: 200;
  }
  .sidebar.open { transform: none; box-shadow: 4px 0 40px rgba(0,0,0,0.5); }
  .menu-btn { display: block; }
  .main-content { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .section-header { flex-direction: column; gap: 10px; }
  .btn-group { flex-wrap: wrap; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 16px; }
  .period-tabs { flex-wrap: wrap; }
}
