/* ===========================================================
   Kos Manager — design system
   A calm, high-density operations console. Slate + amber accent
   (amber = electricity / billing theme, fitting for a kWh-billing tool).
   =========================================================== */

:root {
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e2e8f0;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(15,23,42,0.04), 0 1px 8px rgba(15,23,42,0.04);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

/* Layout shell */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--ink);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
}
.sidebar .brand {
  font-family: var(--font-display);
  color: #fff;
  font-size: 19px;
  font-weight: 600;
  margin-bottom: 4px;
  padding: 0 8px;
}
.sidebar .brand-sub {
  font-size: 11.5px;
  color: var(--amber);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 8px;
  margin-bottom: 28px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar nav a:hover { background: #1e293b; color: #fff; }
.sidebar nav a.active { background: var(--amber); color: #1c1203; font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .user-box {
  padding: 12px 8px;
  border-top: 1px solid #1e293b;
  font-size: 12.5px;
  color: var(--faint);
}
.sidebar .user-box .name { color: #fff; font-weight: 600; display:block; margin-bottom: 6px;}
.sidebar .logout-link { color: var(--faint); font-size: 12.5px; }
.sidebar .logout-link:hover { color: #fff; }

.main { flex: 1; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 18px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 0;
}
.topbar .topbar-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.content { padding: 28px 32px; max-width: 1280px; }

/* Cards / surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px 22px; }
.card-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-header h2 { font-size: 15.5px; font-weight: 600; margin: 0; }

/* Stat tiles */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-tile .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-tile .value { font-family: var(--font-display); font-size: 26px; font-weight: 600; margin-top: 4px; }
.stat-tile .value.amber { color: var(--amber); }
.stat-tile .value.green { color: var(--green); }
.stat-tile .value.red { color: var(--red); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13.8px; }
th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
td.num { text-align: right; font-family: var(--font-mono); font-size: 13px; }
td.center { text-align: center; }

/* Badges */
.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}
.badge-paid { background: var(--green-soft); color: #166534; }
.badge-unpaid { background: var(--amber-soft); color: #92400e; }
.badge-sent { background: #dbeafe; color: #1e40af; }
.badge-notsent { background: #f1f5f9; color: var(--muted); }
.badge-failed { background: var(--red-soft); color: #991b1b; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: filter 0.1s;
}
.btn:hover { filter: brightness(0.95); }
.btn-primary { background: var(--ink); color: #fff; }
.btn-amber { background: var(--amber); color: #1c1203; }
.btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 14px;
  font-family: var(--font-body);
  background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--amber);
  outline-offset: -1px;
  border-color: var(--amber);
}
.field .hint { font-size: 12px; color: var(--faint); margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Login page */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
}
.login-card {
  width: 360px;
  background: var(--surface);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-card .brand { font-family: var(--font-display); font-size: 24px; font-weight: 600; margin-bottom: 2px; }
.login-card .brand-sub { font-size: 12.5px; color: var(--amber); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 26px; }

/* Misc */
.flash {
  padding: 11px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 18px;
}
.flash-error { background: var(--red-soft); color: #991b1b; }
.flash-success { background: var(--green-soft); color: #166534; }
.muted { color: var(--muted); }
.empty-state { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty-state .big { font-size: 32px; margin-bottom: 8px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }

/* Wrap every table in a scroll container on narrow screens instead of letting
   columns get crushed. Applies a horizontal scrollbar only when needed. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr; }
}

/* Phone / small tablet layout: stack the sidebar above the content as a
   horizontally-scrollable nav bar instead of a fixed-width side column,
   which is what was breaking the layout on phones (the 220px sidebar was
   eating ~half the screen width with no way to shrink). */
@media (max-width: 720px) {
  .shell { flex-direction: column; min-height: auto; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    padding: 12px 14px;
    gap: 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar .brand,
  .sidebar .brand-sub {
    display: none; /* save space on phones; property name still shows in the topbar */
  }
  .sidebar nav {
    flex-direction: row;
    gap: 4px;
    flex-shrink: 0;
  }
  .sidebar nav a {
    white-space: nowrap;
    padding: 7px 11px;
    font-size: 13px;
  }
  .sidebar .spacer { display: none; }
  .sidebar .user-box {
    border-top: none;
    border-left: 1px solid #1e293b;
    padding: 6px 0 6px 14px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .sidebar .user-box .name { display: none; }

  .topbar {
    padding: 14px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .topbar h1 { font-size: 18px; }
  .topbar > div:last-child { width: 100%; }

  .content { padding: 16px; }

  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-tile { padding: 12px 14px; }
  .stat-tile .value { font-size: 20px; }

  .card-pad { padding: 14px 16px; }
  .card-header { padding: 12px 16px; }

  table { font-size: 12.5px; }
  th, td { padding: 8px 10px; }

  .login-card { width: 90%; max-width: 360px; padding: 28px 22px; }
}
