/* ── Reset & Base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #1a1a2e;
  --accent:  #e94560;
  --surface: #ffffff;
  --surface2: #f8f9fc;
  --surface3: #eef0f5;
  --border:  #e2e5ee;
  --text:    #1a1a2e;
  --text2:   #6b7280;
  --text3:   #9ca3af;
  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;
  --info:    #3b82f6;
  --radius:  10px;
  --shadow:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 14px rgba(0,0,0,.10);
  --sidebar-w: 224px;
}
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--primary);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--primary);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1000;
  overflow-y: auto;
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.sidebar-logo { padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; justify-content: space-between; }
.logo-text  { font-size: 20px; font-weight: 700; color: #fff; letter-spacing: -.5px; }
.logo-sub   { font-size: 10px; color: rgba(255,255,255,.3); margin-top: 2px; text-transform: uppercase; letter-spacing: 1px; }
.sidebar-nav  { flex: 1; padding: 14px 10px; }
.nav-section  { margin-bottom: 20px; }
.nav-label    { font-size: 10px; font-weight: 600; color: rgba(255,255,255,.28); text-transform: uppercase; letter-spacing: 1.2px; padding: 0 8px; margin-bottom: 5px; }
.nav-item     { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 7px; cursor: pointer; color: rgba(255,255,255,.55); font-size: 13px; font-weight: 500; transition: all .13s; margin-bottom: 1px; text-decoration: none; }
.nav-item:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.9); text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); }
/* Sidebar close button (mobile only) */
.sidebar-close { display: none; background: none; border: none; color: rgba(255,255,255,.5); font-size: 22px; cursor: pointer; line-height: 1; padding: 0; }

/* ── Sidebar overlay (mobile) ───────────────────────────────────── */
/* Overlay handled via inline styles in header.php */

/* ── Main ───────────────────────────────────────────────────────── */
.main    { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; background: var(--surface2); min-width: 0; }
.topbar  { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow); gap: 10px; }
.topbar h1       { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions  { display: flex; gap: 6px; flex-wrap: wrap; flex-shrink: 0; }
/* Hamburger button */
.hamburger { display: none; background: none; border: none; cursor: pointer; padding: 4px; color: var(--text); flex-shrink: 0; }
.hamburger svg { display: block; }
.content { padding: 18px 20px; }

/* ── Cards ──────────────────────────────────────────────────────── */
.card       { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card-title { font-size: 13.5px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.stat-grid  { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card  { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat-label { font-size: 10.5px; color: var(--text2); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 20px; font-weight: 700; }
.stat-sub   { font-size: 11px; color: var(--text3); margin-top: 3px; }
.stat-value.success { color: var(--success); }
.stat-value.danger  { color: var(--danger); }
.stat-value.info    { color: var(--info); }
.stat-value.warning { color: var(--warning); }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn          { display: inline-flex; align-items: center; gap: 5px; padding: 7px 14px; border-radius: 7px; border: none; cursor: pointer; font-size: 12.5px; font-weight: 500; transition: all .13s; text-decoration: none; white-space: nowrap; vertical-align: middle; touch-action: manipulation; }
.btn:hover    { text-decoration: none; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: #c73651; color: #fff; }
.btn-secondary { background: var(--surface3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { background: #059669; color: #fff; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: #dc2626; color: #fff; }
.btn-warning  { background: var(--warning); color: #fff; }
.btn-sm       { padding: 5px 10px; font-size: 11.5px; }
.btn-xs       { padding: 3px 8px; font-size: 11px; }

/* ── Forms ──────────────────────────────────────────────────────── */
.form-group    { margin-bottom: 13px; }
.form-label    { display: block; font-size: 11px; font-weight: 600; color: var(--text2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
.form-control  { width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: 7px; font-size: 14px; color: var(--text); background: var(--surface); outline: none; transition: border .13s; font-family: inherit; -webkit-appearance: none; appearance: none; }
.form-control:focus { border-color: var(--accent); }
select.form-control { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.form-row      { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.form-text     { font-size: 11px; color: var(--text3); margin-top: 3px; }
.required      { color: var(--danger); }
/* File input */
input[type="file"].form-control { padding: 6px 10px; cursor: pointer; }

/* ── Tables ─────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 6px; }
table      { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th         { text-align: left; padding: 9px 11px; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--text2); border-bottom: 2px solid var(--border); background: var(--surface2); white-space: nowrap; }
td         { padding: 9px 11px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }
tfoot td   { background: var(--surface2) !important; font-weight: 700; border-top: 2px solid var(--border); }
.text-right { text-align: right; }
.nowrap     { white-space: nowrap; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge         { display: inline-block; padding: 2px 7px; border-radius: 20px; font-size: 10.5px; font-weight: 600; white-space: nowrap; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: var(--surface3); color: var(--text2); }
.badge-purple  { background: #ede9fe; color: #5b21b6; }
.badge-orange  { background: #ffedd5; color: #9a3412; }

/* ── Alerts ─────────────────────────────────────────────────────── */
.alert         { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* ── Misc ────────────────────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.section-title  { font-size: 15px; font-weight: 600; }
.divider        { height: 1px; background: var(--border); margin: 16px 0; }
.filter-bar     { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 14px; flex-wrap: wrap; }
.filter-bar .form-control { width: auto; min-width: 120px; }
.info-note      { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 7px; padding: 9px 13px; font-size: 12px; color: #1e40af; margin-bottom: 12px; }
.section-divider { background: var(--surface2); border-radius: 7px; padding: 8px 14px; font-size: 12px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .6px; margin: 14px 0 10px; border-left: 3px solid var(--accent); }
.grand-total-box { background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.grand-total-box .label { font-size: 13px; font-weight: 600; color: #92400e; }
.grand-total-box .value { font-size: 24px; font-weight: 800; color: #c2410c; }
.profit-banner  { border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.profit-banner.positive { background: linear-gradient(135deg,#d1fae5,#a7f3d0); border: 1px solid #6ee7b7; }
.profit-banner.negative { background: linear-gradient(135deg,#fee2e2,#fca5a5); border: 1px solid #f87171; }
.profit-label   { font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 4px; }
.profit-amount  { font-size: 28px; font-weight: 800; }
.profit-banner.positive .profit-amount { color: #065f46; }
.profit-banner.negative .profit-amount { color: #991b1b; }
.profit-sub     { font-size: 11px; color: #374151; margin-top: 4px; }
.week-nav       { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.week-display   { font-size: 13px; font-weight: 600; padding: 7px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: 7px; min-width: 180px; text-align: center; }
.trainee-row td { background: #faf5ff !important; }
.trainee-label  { font-size: 10px; color: #7c3aed; font-weight: 600; background: #ede9fe; padding: 1px 5px; border-radius: 4px; margin-left: 4px; }
.empty-state    { text-align: center; padding: 32px 16px; color: var(--text3); font-size: 13px; }

/* ── Login page ─────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--primary); padding: 20px; }
.login-box  { background: var(--surface); border-radius: 14px; padding: 32px 28px; width: 100%; max-width: 360px; box-shadow: var(--shadow-md); }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo .t { font-size: 26px; font-weight: 800; color: var(--primary); }
.login-logo .s { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet (≤ 900px)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 14px 16px; }
  .topbar  { padding: 10px 14px; }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (≤ 768px)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Sidebar hidden off-screen by default on mobile — JS toggles transform */
  .sidebar {
    transform: translateX(-100%) !important;
    width: 280px;
    z-index: 1000 !important;
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
    transition: transform .28s cubic-bezier(.4,0,.2,1) !important;
  }
  .sidebar.open {
    transform: translateX(0) !important;
  }
  .sidebar-close { display: block; }

  /* Main takes full width */
  .main { margin-left: 0; }

  /* Topbar: show hamburger */
  .hamburger { display: flex; align-items: center; }
  .topbar h1 { font-size: 14px; }
  .topbar-actions { gap: 4px; }
  .topbar-actions .btn { padding: 5px 9px; font-size: 11.5px; }

  /* Content padding tighter */
  .content { padding: 12px 12px; }

  /* Stat grid: 2 cols on mobile */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-value { font-size: 17px; }

  /* Cards */
  .card { padding: 12px; }

  /* Forms — single column on small screens */
  .form-row { grid-template-columns: 1fr; }

  /* Filter bar stacks */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .form-control { width: 100%; min-width: unset; }
  .filter-bar > * { width: 100%; }
  .filter-bar div { display: flex; gap: 6px; }

  /* Tables — horizontal scroll with hint */
  .table-wrap { margin: 0 -12px; padding: 0 12px; }
  .table-wrap::after {
    content: '← scroll →';
    display: block;
    text-align: center;
    font-size: 10px;
    color: var(--text3);
    padding: 4px 0 2px;
  }
  table { font-size: 12px; }
  th, td { padding: 7px 8px; }

  /* Buttons in topbar become icon-only for small ones */
  .btn-xs { padding: 3px 6px; }

  /* Week display smaller */
  .week-display { min-width: 0; font-size: 12px; padding: 6px 10px; }

  /* Grand total box */
  .grand-total-box { flex-direction: column; align-items: flex-start; gap: 6px; }
  .grand-total-box .value { font-size: 20px; }

  /* Profit banner */
  .profit-amount { font-size: 22px; }

  /* PnL income/expense grid — stack on mobile */
  div[style*="grid-template-columns:1fr 1fr"] {
    display: flex !important;
    flex-direction: column !important;
  }

  /* Modal fix on mobile */
  div[id$="-modal"] > div,
  div[id="pay-modal"] > div {
    width: 95vw !important;
    max-height: 90vh;
    overflow-y: auto;
    padding: 16px !important;
  }

  /* Topbar actions wrap better */
  .topbar { flex-wrap: nowrap; }

  /* Section divider */
  .section-divider { font-size: 11px; padding: 6px 10px; }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Small mobile (≤ 420px)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 420px) {
  .stat-grid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 13px; max-width: 140px; }
  .topbar-actions .btn span:not(:first-child) { display: none; } /* hide button text, keep icon */
  .content { padding: 10px; }
  .card { padding: 10px; border-radius: 8px; }
  table { font-size: 11.5px; }
  th, td { padding: 6px 7px; }
  .badge { font-size: 9.5px; padding: 1px 5px; }
}
