/* =====================================================================
   Mfumo wa Mashine — Stylesheet
   Light theme (white + red emphasis) by default, dark mode via
   [data-theme="dark"] on <html>. No build step — plain CSS + variables.
   ===================================================================== */

:root,
[data-theme="light"] {
  --bg: #F7F7F8;
  --surface: #FFFFFF;
  --surface-2: #F2F3F5;
  --surface-glass: rgba(255, 255, 255, 0.72);
  --border: #E5E7EB;
  --text: #16181D;
  --text-dim: #6B7280;
  --text-faint: #9CA3AF;

  --red: #E11D2E;
  --red-dim: #e8fdfc;
  --red-strong: #B8121F;
  --green: #15803D;
  --green-dim: #E7F6EC;
  --blue: #1D4ED8;
  --blue-dim: #E8EFFD;
  --amber: #B45309;
  --amber-dim: #FCF1DF;

  --shadow: 0 4px 20px rgba(16, 18, 22, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 18, 22, 0.12);
}

[data-theme="dark"] {
  --bg: #0E1013;
  --surface: #181B21;
  --surface-2: #21252D;
  --surface-glass: rgba(24, 27, 33, 0.72);
  --border: #2C313B;
  --text: #ECEEF1;
  --text-dim: #9AA3B2;
  --text-faint: #626B7A;

  --red: #FF4D5E;
  --red-dim: #33161A;
  --red-strong: #FF7683;
  --green: #4ADE80;
  --green-dim: #14291D;
  --blue: #7DA9F5;
  --blue-dim: #182A47;
  --amber: #F0B45E;
  --amber-dim: #2E2312;

  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}
.mono { font-family: 'Roboto Mono', monospace; }
a { color: inherit; }

/* ---------------------------------------------------------------------
   Auth pages (login / setup)
--------------------------------------------------------------------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.brand-mark {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; margin: 0 auto 16px auto;
}
.auth-title { text-align: center; font-size: 19px; font-weight: 800; margin: 0 0 4px 0; }
.auth-sub { text-align: center; font-size: 12.5px; color: var(--text-faint); margin: 0 0 22px 0; }
.auth-form .field { margin-bottom: 16px; }
.alert-error {
  background: var(--red-dim); color: var(--red-strong); border: 1px solid var(--red);
  padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
}
.alert-success {
  background: var(--green-dim); color: var(--green); border: 1px solid var(--green);
  padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
}

/* ---------------------------------------------------------------------
   Form fields (shared everywhere)
--------------------------------------------------------------------- */
label {
  display: block; font-size: 11.5px; color: var(--text-dim);
  margin-bottom: 6px; font-weight: 600; letter-spacing: 0.2px;
}
input[type=text], input[type=number], input[type=date], input[type=password], select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 14.5px;
  font-family: 'Inter', sans-serif;
  outline: none;
  min-height: 44px;
  transition: border-color .15s;
}
input:focus, select:focus { border-color: var(--red); }
input[readonly] { color: var(--text-dim); cursor: not-allowed; }
input::placeholder { color: var(--text-faint); }

.btn-primary {
  width: 100%; background: var(--red); color: #fff; border: none;
  padding: 13px; border-radius: 10px; font-weight: 700; font-size: 14.5px;
  cursor: pointer; min-height: 46px; transition: filter .15s, transform .05s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { background: var(--surface-2); color: var(--text-faint); cursor: not-allowed; }

.btn-ghost {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  padding: 9px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.btn-ghost:hover { border-color: var(--red); color: var(--red); }

/* ---------------------------------------------------------------------
   App shell / topbar
--------------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface-glass);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border-bottom: 1px solid var(--border);
}
.who { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--red-dim); color: var(--red-strong);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; border: 1px solid var(--red);
}
.who-name { font-size: 13.5px; font-weight: 700; line-height: 1.2; }
.who-role { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.4px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.theme-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}

.container { max-width: 1180px; margin: 0 auto; padding: 20px; padding-bottom: 100px; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-head h2 { margin: 0; font-size: 18px; font-weight: 800; }

/* Hide manager-only controls for employees (dashboard.php sets body.is-manager) */
.manager-only { display: none; }
body.is-manager .manager-only { display: revert; }
body.is-manager td.manager-only { display: table-cell; }
body.is-manager th.manager-only { display: table-cell; }

.user-photo {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border); background: var(--surface-2);
}
.user-photo-placeholder {
  width: 36px; height: 36px; border-radius: 50%; background: var(--red-dim); color: var(--red-strong);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  border: 1px solid var(--border);
}
.role-badge {
  font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.3px;
}
.role-badge.manager { background: var(--red-dim); color: var(--red-strong); }
.role-badge.employee { background: var(--blue-dim); color: var(--blue); }

/* ---------------------------------------------------------------------
   Chart section
--------------------------------------------------------------------- */
.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.chart-card h3 { margin: 0 0 4px 0; font-size: 14px; font-weight: 800; }
.chart-card .sub { font-size: 11.5px; color: var(--text-faint); margin-bottom: 14px; }
.chart-mount svg text { fill: var(--text-dim); font-family: 'Inter', sans-serif; }

/* ---------------------------------------------------------------------
   Month scope banner
--------------------------------------------------------------------- */
.scope-banner {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  background: var(--red-dim); border: 1px solid var(--green); color: var(--red-strong);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 12.5px; font-weight: 600;
}
.scope-banner a { color: var(--red-strong); text-decoration: underline; }

/* ---------------------------------------------------------------------
   Stat cards
--------------------------------------------------------------------- */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px;
}
@media (max-width: 700px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 15px 16px; box-shadow: var(--shadow);
}
.stat-card .eyebrow { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-faint); font-weight: 700; margin-bottom: 7px; }
.stat-card .val { font-family: 'Roboto Mono', monospace; font-size: 20px; font-weight: 700; }
.stat-card.token .val { color: var(--amber); }
.stat-card.total .val { color: var(--green); }
.stat-card.bonasi .val { color: var(--blue); }
.stat-card.hasara .val { color: var(--red); }

/* ---------------------------------------------------------------------
   Entry form card
--------------------------------------------------------------------- */
.form-card {
  max-width: 620px;
  margin: 0 auto 28px auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px; box-shadow: var(--shadow);
}
.form-card h2 { font-size: 15px; margin: 0 0 4px 0; font-weight: 800; }
.form-card .sub { font-size: 12.5px; color: var(--text-faint); margin-bottom: 18px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .row2 { grid-template-columns: 1fr; } }
.field { margin-bottom: 14px; }

.chip-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.readonly-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.readonly-chip .lbl { font-size: 10px; color: var(--text-faint); text-transform: uppercase; margin-bottom: 4px; }
.readonly-chip .v { font-family: 'Roboto Mono', monospace; font-size: 13.5px; font-weight: 700; color: var(--text-dim); }

.preview-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0; }
@media (max-width: 560px) { .preview-grid { grid-template-columns: repeat(2, 1fr); } }
.digit-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 11px 8px; text-align: center; }
.digit-box .lbl { font-size: 9.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 5px; }
.digit-box .num { font-family: 'Roboto Mono', monospace; font-size: 15px; font-weight: 700; }
.digit-box.token .num { color: var(--amber); }
.digit-box.total .num { color: var(--green); }
.digit-box.bonasi .num { color: var(--blue); }
.digit-box.faida .num { color: #9333EA; }
[data-theme="dark"] .digit-box.faida .num { color: #C99CE8; }

.malipo-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.malipo-btn {
  padding: 12px; border-radius: 10px; text-align: center; cursor: pointer;
  background: var(--surface-2); border: 1.5px solid var(--border); font-size: 13.5px; font-weight: 700;
}
.malipo-btn.tick.active { border-color: var(--green); background: var(--green-dim); color: var(--green); }
.malipo-btn.cross.active { border-color: var(--red); background: var(--red-dim); color: var(--red); }

.hint { font-size: 11px; color: var(--text-faint); margin-top: 10px; line-height: 1.5; text-align: center; }

/* ---------------------------------------------------------------------
   Toolbar (search / filters / export) — manager view
--------------------------------------------------------------------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--surface-glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin-bottom: 16px;
}
.toolbar input, .toolbar select { min-height: 40px; font-size: 13px; }
.toolbar .search-field { flex: 1 1 200px; }
.toolbar .filter-field { flex: 0 1 150px; }
.toolbar .btn-export {
  background: var(--green); color: #fff; border: none; border-radius: 8px;
  padding: 10px 16px; font-weight: 700; font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.toolbar .btn-export:hover { filter: brightness(1.08); }
.toolbar .btn-clear { flex: 0 0 auto; }

/* ---------------------------------------------------------------------
   Manager table
--------------------------------------------------------------------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  overflow: auto; box-shadow: var(--shadow); max-width: 100%;
  max-height: min(65vh, 640px); /* records scroll inside here, page itself doesn't grow endlessly */
}
table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 1100px; }
thead th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-faint); padding: 12px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap; font-weight: 700; background: var(--surface-2); position: sticky; top: 0;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; color: var(--text); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.c-amber { color: var(--amber); font-weight: 600; }
.c-green { color: var(--green); font-weight: 600; }
.c-blue { color: var(--blue); font-weight: 600; }
.c-red { color: var(--red); }
.c-dim { color: var(--text-faint); }
.edited-tag { font-size: 10px; color: var(--text-faint); }
.empty-cell { text-align: center; padding: 44px 14px; color: var(--text-faint); }
.actions { display: flex; gap: 6px; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; cursor: pointer;
}
.icon-btn.edit:hover { color: var(--amber); border-color: var(--amber); }
.icon-btn.danger:hover { color: var(--red); border-color: var(--red); }

/* ---------------------------------------------------------------------
   Employee card list (mobile-friendly, also used as a general
   responsive card component)
--------------------------------------------------------------------- */
.cards-wrap { display: flex; flex-direction: column; gap: 10px; max-width: 620px; margin: 0 auto; }
.entry-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.entry-head { padding: 13px 14px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.entry-title { display: flex; align-items: center; gap: 9px; }
.machine-chip { font-family: 'Roboto Mono', monospace; font-size: 11px; font-weight: 700; background: var(--red-dim); color: var(--red-strong); padding: 4px 8px; border-radius: 6px; }
.entry-sehemu { font-size: 13.5px; font-weight: 700; }
.entry-date { font-size: 10.5px; color: var(--text-faint); margin-top: 2px; }
.entry-right { display: flex; align-items: center; gap: 8px; }
.chev { color: var(--text-faint); font-size: 12px; transition: transform .2s; }
.entry-card.open .chev { transform: rotate(180deg); }
.entry-body { display: none; padding: 0 14px 14px 14px; border-top: 1px solid var(--border); }
.entry-card.open .entry-body { display: block; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.kv { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; }
.kv .lbl { font-size: 9px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-faint); margin-bottom: 4px; }
.kv .num { font-family: 'Roboto Mono', monospace; font-size: 13.5px; font-weight: 700; }
.kv.tok .num { color: var(--amber); }
.kv.tot .num { color: var(--green); }
.kv.bon .num { color: var(--blue); }
.kv.fai .num { color: #9333EA; }
[data-theme="dark"] .kv.fai .num { color: #C99CE8; }
.hasara-line { margin-top: 10px; font-size: 12px; color: var(--red); }
.kituo-line { margin-top: 4px; font-size: 12px; color: var(--text-dim); }
.filled-by { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-dim); }
.filled-by b { color: var(--text); }
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-faint); font-size: 13px; }

/* ---------------------------------------------------------------------
   FAB + modal sheet
--------------------------------------------------------------------- */
.fab {
  position: fixed; bottom: 22px; right: 22px; z-index: 25;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--red); color: #fff; border: none;
  font-size: 26px; font-weight: 700; cursor: pointer;
  box-shadow: 0 8px 20px rgba(225, 29, 46, 0.35);
  display: flex; align-items: center; justify-content: center;
}
.fab:hover { filter: brightness(1.08); }

#backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(10, 10, 12, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: none; opacity: 0; transition: opacity .2s;
}
#backdrop.show { display: block; opacity: 1; }

#sheet {
  position: fixed; left: 50%; bottom: 0; transform: translate(-50%, 100%);
  width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0; z-index: 41;
  transition: transform .28s cubic-bezier(.32,.72,0,1), opacity .2s;
  padding-bottom: 24px; box-shadow: var(--shadow-lg);
  display: none; /* JS toggles this to block right before animating in —
                     guarantees a closed sheet can NEVER intercept clicks,
                     unlike opacity/pointer-events which are easy to get
                     subtly wrong across breakpoints */
}
#sheet.show { display: block; transform: translate(-50%, 0); }
@media (min-width: 700px) {
  #sheet { top: 50%; bottom: auto; transform: translate(-50%, -40%); border-radius: 18px; opacity: 0; }
  #sheet.show { transform: translate(-50%, -50%); opacity: 1; }
}
.sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 99px; margin: 10px auto 4px auto; }
@media (min-width: 700px) { .sheet-handle { display: none; } }
.sheet-head { padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.sheet-head h3 { margin: 0; font-size: 15px; font-weight: 800; }
.sheet-close { background: none; border: none; color: var(--text-faint); font-size: 20px; cursor: pointer; padding: 4px; }
.sheet-body { padding: 18px 20px 4px 20px; }

/* ---------------------------------------------------------------------
   Toast notifications
--------------------------------------------------------------------- */
#toast-container {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 8px;
  width: calc(100% - 32px); max-width: 420px; pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(-12px);
  transition: opacity .2s, transform .2s;
  border: 1px solid var(--border);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--green-dim); color: var(--green); border-color: var(--green); }
.toast.error { background: var(--red-dim); color: var(--red-strong); border-color: var(--red); }