:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --overdue: #dc2626;
  --week: #ea580c;
  --month: #2563eb;
  --ok: #16a34a;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* page itself doesn't scroll — only the table does */
}
a { color: var(--brand); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--card); padding: 36px; border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 380px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p.sub { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand); color: #fff; border: none; padding: 10px 16px;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--brand-dark); }
.btn.full { width: 100%; margin-top: 20px; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f9fafb; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.danger { background: var(--overdue); }

.error { color: var(--overdue); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- App shell ---------- */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 12px 24px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; margin: 0; display: flex; align-items: center; gap: 8px; }
.topbar .who { color: var(--muted); font-size: 13px; margin-right: 12px; }
.container { max-width: 1700px; width: 100%; margin: 0 auto; padding: 20px 24px 20px; flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- Summary cards ---------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.scard {
  background: var(--card); border-radius: 12px; padding: 16px; box-shadow: var(--shadow);
  cursor: pointer; border: 2px solid transparent; transition: border-color .15s;
}
.scard:hover { border-color: var(--line); }
.scard.active { border-color: var(--brand); }
.scard .num { font-size: 30px; font-weight: 700; line-height: 1; }
.scard .lbl { color: var(--muted); font-size: 13px; margin-top: 6px; }
.scard.c-overdue .num { color: var(--overdue); }
.scard.c-week .num { color: var(--week); }
.scard.c-month .num { color: var(--month); }
.scard.c-total .num { color: var(--ink); }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; gap: 12px; align-items: end; flex-wrap: wrap;
  background: var(--card); padding: 16px; border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.toolbar .field { display: flex; flex-direction: column; }
.toolbar .field label { margin-top: 0; }
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar .spacer { flex: 1; }

/* ---------- Table ---------- */
.table-wrap { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); overflow: auto; flex: 1; min-height: 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
/* Keep IDs, dates, service, status and actions on one line; let text columns wrap */
th:nth-child(1), td:nth-child(1), th:nth-child(2), td:nth-child(2),
th:nth-child(6), td:nth-child(6), th:nth-child(7), td:nth-child(7),
th:nth-child(8), td:nth-child(8), th:nth-child(9), td:nth-child(9),
th:nth-child(10), td:nth-child(10), th:nth-child(11), td:nth-child(11) { white-space: nowrap; }
th { background: #f9fafb; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); position: sticky; top: 0; z-index: 3; }
tbody tr:hover { background: #f9fafb; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.overdue { background: #fee2e2; color: var(--overdue); }
.badge.today   { background: #fee2e2; color: var(--overdue); }
.badge.week    { background: #ffedd5; color: var(--week); }
.badge.month   { background: #dbeafe; color: var(--month); }
.badge.ok      { background: #dcfce7; color: var(--ok); }
.badge.none    { background: #f3f4f6; color: var(--muted); }
.badge.special { background: #fef3c7; color: #b45309; }
.btn.ghost.active-filter { background: #fef3c7; color: #b45309; border-color: #fcd34d; }
.sa-toggle { cursor: pointer; font-size: 17px; line-height: 1; user-select: none; color: #cbd5e1; }
.sa-toggle:hover { color: #f59e0b; }
.sa-toggle.on { color: #f59e0b; }

/* Action dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); z-index: 40; min-width: 230px; overflow: hidden;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
  display: block; width: 100%; text-align: left; padding: 11px 14px;
  background: #fff; border: none; cursor: pointer; font-size: 14px; color: var(--ink);
}
.dropdown-item:hover { background: #f3f4f6; }

/* Multi-select checkbox dropdown (Company / Department filters) */
.ms { position: relative; }
.ms-btn {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; text-align: left; cursor: pointer; font-size: 14px; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ms-btn:hover { border-color: #cbd5e1; }
.ms-panel {
  display: none; position: absolute; left: 0; top: calc(100% + 4px);
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  z-index: 40; min-width: 100%; width: max-content; max-width: 320px; max-height: 300px;
  overflow-y: auto; padding: 6px;
}
.ms-panel.open { display: block; }
.ms-header {
  display: flex; gap: 8px; justify-content: space-between;
  position: sticky; top: 0; background: #fff; z-index: 1;
  padding: 2px 6px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.ms-link { background: none; border: none; color: var(--brand); cursor: pointer; font-size: 13px; font-weight: 600; padding: 2px 4px; }
.ms-link:hover { text-decoration: underline; }
.ms-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; margin: 0;
  font-size: 14px; font-weight: 400; cursor: pointer; border-radius: 6px;
}
.ms-item:hover { background: #f3f4f6; }
.ms-item input { width: auto; margin: 0; }
.ms-empty { padding: 8px; color: var(--muted); font-size: 13px; }

/* Filtered-count indicators next to filter labels */
.filter-count { color: var(--brand); font-weight: 700; }
.filter-count-label { color: var(--brand); font-weight: 700; text-align: center; min-height: 18px; }

.row-actions { display: flex; gap: 6px; }
.btn.ghost.danger-text { color: var(--overdue); }
.btn.ghost.danger-text:hover { background: #fee2e2; }
th[data-sort]:hover { color: var(--ink); background: #f1f5f9; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(17,24,39,.5); display: none;
  align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal-bg.show { display: flex; }
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 560px; padding: 24px;
  max-height: 90vh; overflow: auto;
}
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 8px;
  font-size: 14px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 99;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--overdue); }

.upload-box {
  border: 2px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center;
}

@media (max-width: 720px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}
