/* ═══════════════════════════════════════════════════════════════════════════════
   KEBUN GROUP — Design System v2
   Shared CSS: tokens, dark mode, sidebar, components, animations, responsive
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── FONTS ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ══════════════════════════════════════════════════════════════════════════════
   DESIGN TOKENS — LIGHT MODE (default)
   ══════════════════════════════════════════════════════════════════════════════ */
:root {
  /* Background */
  --bg-0: #fafaf9;
  --bg-1: #ffffff;
  --bg-2: #f5f5f4;
  --bg-3: #e7e5e4;

  /* Surface */
  --surface: #ffffff;
  --surface-hover: #fafaf9;
  --surface-active: #f5f5f4;

  /* Border */
  --border: #e7e5e4;
  --border-hover: #d6d3d1;
  --border-active: #a8a29e;

  /* Text */
  --text: #1c1917;
  --text-2: #57534e;
  --text-3: #a8a29e;
  --text-inv: #fafaf9;

  /* Accent Colors */
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --green-text: #15803d;

  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --red-text: #b91c1c;

  --amber: #d97706;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --amber-text: #92400e;

  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --blue-border: #bfdbfe;
  --blue-text: #1d4ed8;

  --purple: #7c3aed;
  --purple-bg: #f5f3ff;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 28px;

  /* Spacing & Radius */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);

  /* Sidebar */
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 60px;
  --header-h: 52px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 0.15s;
  --duration-md: 0.25s;
  --duration-lg: 0.35s;
}

/* ══════════════════════════════════════════════════════════════════════════════
   DARK MODE
   ══════════════════════════════════════════════════════════════════════════════ */
[data-theme="dark"] {
  --bg-0: #0c0a09;
  --bg-1: #1c1917;
  --bg-2: #292524;
  --bg-3: #44403c;

  --surface: #1c1917;
  --surface-hover: #292524;
  --surface-active: #44403c;

  --border: #292524;
  --border-hover: #44403c;
  --border-active: #57534e;

  --text: #fafaf9;
  --text-2: #a8a29e;
  --text-3: #57534e;
  --text-inv: #1c1917;

  --green: #4ade80;
  --green-bg: #052e16;
  --green-border: #166534;
  --green-text: #86efac;

  --red: #f87171;
  --red-bg: #450a0a;
  --red-border: #7f1d1d;
  --red-text: #fca5a5;

  --amber: #fbbf24;
  --amber-bg: #451a03;
  --amber-border: #78350f;
  --amber-text: #fde68a;

  --blue: #60a5fa;
  --blue-bg: #172554;
  --blue-border: #1e40af;
  --blue-text: #93c5fd;

  --purple: #a78bfa;
  --purple-bg: #2e1065;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
}

/* ══════════════════════════════════════════════════════════════════════════════
   RESET & BASE
   ══════════════════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  background: var(--bg-0);
  font-family: var(--font);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background var(--duration-md) var(--ease), color var(--duration-md) var(--ease);
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ══════════════════════════════════════════════════════════════════════════════
   LAYOUT: SIDEBAR + HEADER + CONTENT
   ══════════════════════════════════════════════════════════════════════════════ */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas: "sidebar header" "sidebar content";
  min-height: 100vh;
  transition: grid-template-columns var(--duration-md) var(--ease);
}
.app-layout.sidebar-collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* ── SIDEBAR ── */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
  transition: width var(--duration-md) var(--ease), background var(--duration-md) var(--ease);
}
.sidebar-brand {
  padding: 16px 16px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  min-height: var(--header-h);
}
.sidebar-brand-icon {
  width: 28px; height: 28px;
  background: var(--green);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.sidebar-brand-text {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-brand-text span { color: var(--text-3); }

.sidebar-nav { flex: 1; padding: 12px 8px; }
.sidebar-section {
  margin-bottom: 16px;
}
.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 12px 6px;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: var(--text-base);
  font-weight: 500;
  text-decoration: none;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-link:hover {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
}
.sidebar-link.active {
  background: var(--green-bg);
  color: var(--green-text);
  font-weight: 600;
}
.sidebar-link svg, .sidebar-link .nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}
.sidebar-link.active svg, .sidebar-link.active .nav-icon { opacity: 1; }
.sidebar-link .nav-label { overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

/* Collapsed sidebar */
.sidebar-collapsed .sidebar-brand-text,
.sidebar-collapsed .sidebar-section-label,
.sidebar-collapsed .sidebar-link .nav-label { display: none; }
.sidebar-collapsed .sidebar-link { justify-content: center; padding: 10px; }
.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 16px 8px 12px; }

/* ── HEADER ── */
.app-header {
  grid-area: header;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 150;
  backdrop-filter: blur(8px);
  transition: background var(--duration-md) var(--ease);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--text-sm);
  color: var(--text-3);
}
.breadcrumb a { color: var(--text-3); text-decoration: none; }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { color: var(--text-3); }
.breadcrumb .current { color: var(--text); font-weight: 500; }

/* ── CONTENT ── */
.app-content {
  grid-area: content;
  padding: 24px;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
}

/* ══════════════════════════════════════════════════════════════════════════════
   COMPONENTS
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-1);
  color: var(--text);
  font-size: var(--text-base);
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-hover); box-shadow: var(--shadow-xs); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary { background: var(--text); color: var(--text-inv); border-color: var(--text); }
.btn-primary:hover { opacity: 0.9; }

.btn-green { background: var(--green); color: white; border-color: var(--green); }
.btn-green:hover { opacity: 0.9; }

.btn-danger { background: var(--red-bg); color: var(--red-text); border-color: var(--red-border); }
.btn-danger:hover { background: var(--red); color: white; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-icon {
  width: 32px; height: 32px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  background: transparent; border: 1px solid transparent;
  color: var(--text-2); cursor: pointer;
  transition: all var(--duration) var(--ease);
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }

/* ── CARDS ── */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  transition: all var(--duration) var(--ease);
}
.card:hover { border-color: var(--border-hover); box-shadow: var(--shadow-sm); }
.card-clickable { cursor: pointer; }
.card-clickable:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* ── PANELS ── */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
  transition: border-color var(--duration) var(--ease);
}
.panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
.panel-title { font-size: var(--text-md); font-weight: 600; }
.panel-body { padding: 18px; }

/* ── STAT CARDS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  transition: all var(--duration) var(--ease);
}
.stat-card:hover { border-color: var(--border-hover); }
.stat-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.stat-val {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.stat-sub { font-size: var(--text-xs); color: var(--text-3); margin-top: 4px; }

/* ── TABLES ── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  white-space: nowrap;
  position: sticky; top: 0;
}
thead th.num { text-align: right; }
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  transition: background var(--duration) var(--ease);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-hover); }
tfoot td {
  padding: 10px 14px;
  font-weight: 600;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
}
.mono { font-family: var(--font-mono); }
.num { text-align: right; }
.empty { text-align: center; padding: 48px 20px; color: var(--text-3); }

/* ── FORMS ── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input, .field select, .field textarea {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-0);
  color: var(--text);
  font-size: var(--text-base);
  font-family: var(--font);
  transition: all var(--duration) var(--ease);
}
.field textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
  background: var(--bg-1);
}

/* ── BADGES ── */
.badge {
  display: inline-flex; align-items: center;
  font-size: 10px; font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
}
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-red { background: var(--red-bg); color: var(--red-text); }
.badge-amber { background: var(--amber-bg); color: var(--amber-text); }
.badge-blue { background: var(--blue-bg); color: var(--blue-text); }
.badge-neutral { background: var(--bg-2); color: var(--text-2); }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--text); color: var(--text-inv);
  padding: 12px 18px; border-radius: var(--radius-lg);
  font-size: var(--text-base); font-weight: 500;
  z-index: 9999;
  opacity: 0; transform: translateY(8px);
  transition: all var(--duration-md) var(--ease);
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--red); color: white; }
.toast.ok { background: var(--green); color: white; }

/* ── MODAL ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center; justify-content: center;
  animation: fadeIn var(--duration-md) var(--ease);
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  width: min(520px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp var(--duration-md) var(--ease);
}

/* ── DARK MODE TOGGLE ── */
.theme-toggle {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-1);
  cursor: pointer;
  color: var(--text-2);
  transition: all var(--duration) var(--ease);
}
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ══════════════════════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ══════════════════════════════════════════════════════════════════════════════ */
.text-green { color: var(--green-text); }
.text-red { color: var(--red-text); }
.text-amber { color: var(--amber-text); }
.text-blue { color: var(--blue-text); }
.text-muted { color: var(--text-2); }
.text-faint { color: var(--text-3); }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 600; }

/* ══════════════════════════════════════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════════════════════════════════════ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

.animate-in { animation: slideUp var(--duration-md) var(--ease) both; }
.skeleton {
  background: linear-gradient(90deg, var(--bg-2) 25%, var(--bg-3) 50%, var(--bg-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE SIDEBAR → BOTTOM NAV / OVERLAY
   ══════════════════════════════════════════════════════════════════════════════ */
/* ══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE SIDEBAR → BOTTOM NAV / OVERLAY
   ══════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas: "header" "content";
  }
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    width: 280px;
    height: 100vh;
    z-index: 300;
    transition: left var(--duration-md) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 250;
  }
  .sidebar.open ~ .sidebar-overlay { display: block; }

  .app-content { padding: 16px 12px; }
  .app-header { padding: 0 12px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }

  /* Fix filter bars on mobile */
  .filter-strip { flex-direction: column; gap: 6px; }
  .filter-strip .field { width: 100%; }
  .filter-strip input, .filter-strip select { width: 100%; }

  /* Fix panel headers wrapping */
  .panel-header { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* Fix hero grid */
  .hero-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .hero-card { padding: 12px 14px; }
  .hero-val { font-size: 16px; }

  /* Fix netto banner */
  .netto-banner { flex-direction: column; align-items: flex-start; padding: 14px 16px; }
  .netto-val { font-size: 22px; }
  .netto-breakdown { gap: 14px; }

  /* Fix tabs overflow */
  .tabs, .app-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .tab, .app-tab { flex-shrink: 0; font-size: 12px; padding: 6px 12px; }

  /* Fix tables */
  table { font-size: 12px; }
  thead th, tbody td, tfoot td { padding: 8px 8px; }

  /* Fix buttons in header */
  .header-actions { gap: 4px; }
  .header-actions .btn { padding: 5px 8px; font-size: 11px; }
  .header-actions .btn span, .header-actions .btn:not(.theme-toggle):not(.btn-icon) { font-size: 0; }
  .header-actions .btn svg { width: 16px; height: 16px; }
  .header-actions a.btn, .header-actions button.btn { padding: 6px; }

  /* Period bar mobile */
  .period-bar { flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 12px; }
  .period-bar select, .period-bar input { width: 100%; }
  .qbtn { font-size: 10px; padding: 0 8px; height: 26px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .app-content { padding: 12px 8px; }
  .hero-grid { grid-template-columns: 1fr; }
  .rate-cards { grid-template-columns: 1fr 1fr; }
  .netto-breakdown { flex-direction: column; gap: 8px; }
}
