:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-h: #1d4ed8;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --pill: #eef2ff;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", "Microsoft JhengHei",
    "PingFang TC", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
button {
  cursor: pointer; padding: 6px 12px; border: 1px solid var(--border);
  background: #fff; border-radius: 6px; font-size: 14px;
}
button:hover { background: #f3f4f6; }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover { background: var(--primary-h); }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button.icon { background: transparent; border: none; font-size: 22px; padding: 0 6px; }
input, select, textarea {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; margin-bottom: 12px;
}
.muted { color: var(--muted); }
.overdue { color: var(--danger); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spacer { flex: 1; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Login page */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb); padding: 20px;
}
.login-card {
  background: #fff; border-radius: 12px; padding: 32px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2); width: 100%; max-width: 380px;
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-card .sub { color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.login-card input { width: 100%; margin-bottom: 12px; }
.login-card .err { color: var(--danger); font-size: 13px; min-height: 18px; }
.version-tag {
  margin-top: 14px; text-align: center; font-size: 11px;
  color: #9ca3af; letter-spacing: 0.5px; font-family: monospace;
}

/* App shell */
.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 10px 16px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 600; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav button.tab {
  padding: 6px 12px; border: 1px solid transparent; background: transparent; color: var(--text);
}
.topbar nav button.tab.active {
  background: var(--pill); border-color: var(--primary); color: var(--primary);
}
.topbar .user { display: flex; align-items: center; gap: 8px; }
#bell { position: relative; cursor: pointer; padding: 4px 8px; }
#bell .badge {
  background: var(--danger); color: #fff; border-radius: 10px; padding: 1px 6px;
  font-size: 11px; font-weight: 600;
}
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px;
        background: var(--pill); color: var(--primary); }
.pill.sev-critical { background: #fee2e2; color: #b91c1c; }
.pill.sev-high { background: #fef3c7; color: #b45309; }
.pill.sev-medium { background: #e0e7ff; color: #4338ca; }
.pill.sev-low { background: #ecfdf5; color: #047857; }
.main { padding: 16px; max-width: 1320px; margin: 0 auto; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; vertical-align: top; }
th { background: #f9fafb; font-weight: 600; font-size: 13px; }

/* KPI */
.kpi-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.kpi {
  background: var(--pill); border-radius: 8px; padding: 10px 16px;
  cursor: pointer; min-width: 120px; display: flex; flex-direction: column; gap: 4px;
  color: var(--primary); font-size: 13px;
}
.kpi b { font-size: 22px; }
.kpi.danger { background: #fee2e2; color: #b91c1c; cursor: default; }

/* Form */
.form-row { display: flex; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.form-row label { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 160px; font-size: 13px; }
.form-row textarea, .form-row input, .form-row select { width: 100%; }

/* Modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-card {
  background: #fff; border-radius: 10px; width: min(640px, 92vw);
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; flex: 1; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* Notification */
.notif-list { list-style: none; padding: 0; margin: 0; max-height: 60vh; overflow-y: auto; }
.notif-list li {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; border-left: 3px solid transparent;
}
.notif-list li.unread { border-left-color: var(--primary); background: #f8fafc; }
.notif-list li .t { font-weight: 500; }
.notif-list li .meta { font-size: 11px; margin-top: 4px; }
.notif-list li:hover { background: #f3f4f6; }

/* History */
.hist { list-style: none; padding: 0; margin: 0; }
.hist li { padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }

/* Dept */
.dept { margin: 8px 0; }
.dept h4 { margin: 8px 0; }

/* Toast */
.toast {
  position: fixed; top: 20px; right: 20px; padding: 10px 16px;
  background: #1f2937; color: #fff; border-radius: 6px; z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2); font-size: 14px;
}
.toast-ok { background: var(--ok); }
.toast-err { background: var(--danger); }
