/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  transition: background .2s, color .2s;
}
a { text-decoration: none; cursor: pointer; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  position: relative;
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow2);
}
.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 28px;
}
.login-logo-icon {
  width: 42px; height: 42px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px; color: #fff;
}
.login-logo-name  { font-size: 18px; font-weight: 600; }
.login-logo-sub   { font-size: 12px; color: var(--text2); }
.login-title      { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.login-desc       { color: var(--text2); margin-bottom: 24px; font-size: 13px; }
.theme-toggle-float {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 50%; width: 44px; height: 44px;
  font-size: 18px; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow2); transition: transform .15s;
}
.theme-toggle-float:hover { transform: scale(1.1); }

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: width .2s;
  overflow: hidden;
}
.sidebar.collapsed { width: 56px; }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-badge { display: none; }
.sidebar.collapsed .sidebar-collapse { transform: rotate(180deg); }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; }
.sidebar-logo-icon {
  width: 30px; height: 30px; min-width: 30px;
  background: var(--accent); border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
}
.sidebar-logo-name { font-size: 13px; font-weight: 600; white-space: nowrap; }
.sidebar-logo-sub  { font-size: 10px; color: var(--text2); white-space: nowrap; }
.sidebar-collapse {
  background: none; border: none; color: var(--text2);
  font-size: 18px; padding: 2px 4px; border-radius: 4px;
  transition: transform .2s, background .15s;
  flex-shrink: 0;
}
.sidebar-collapse:hover { background: var(--surface); color: var(--text); }

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.avatar {
  width: 30px; height: 30px; min-width: 30px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
}
.sidebar-user-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 10px; color: var(--text2); white-space: nowrap; }

.sidebar-nav {
  flex: 1;
  padding: 8px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}
.nav-section-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text3); padding: 10px 8px 4px;
  white-space: nowrap;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: var(--r2);
  color: var(--text2); font-size: 13px; font-weight: 400;
  transition: background .12s, color .12s;
  cursor: pointer; border: none; background: none; width: 100%;
  white-space: nowrap;
}
.nav-item:hover  { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--red); color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 10px;
  min-width: 18px; text-align: center;
}
.nav-badge:empty { display: none; }

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
}
.theme-toggle {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 7px 8px; border-radius: var(--r2);
  background: none; border: none; color: var(--text2);
  font-size: 13px; cursor: pointer;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.theme-toggle:hover { background: var(--surface); color: var(--text); }
.logout-btn { color: var(--red) !important; }
.logout-btn:hover { background: var(--red-bg) !important; }

/* ── MAIN ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  transition: margin-left .2s;
  background: var(--bg);
}
.sidebar.collapsed ~ .main-content { margin-left: 56px; }

.page { display: none; padding: 28px 32px; max-width: 1200px; }
.page.active { display: block; }

/* ============================================================
   COMPONENTS
   ============================================================ */

/* Page header */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; gap: 16px;
}
.page-header-left {}
.page-title { font-size: 22px; font-weight: 600; margin-bottom: 3px; }
.page-sub   { color: var(--text2); font-size: 13px; }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
}
.stat-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 600; line-height: 1; }
.stat-value.c-accent { color: var(--accent); }
.stat-value.c-green  { color: var(--green); }
.stat-value.c-amber  { color: var(--amber); }
.stat-value.c-red    { color: var(--red); }
.stat-delta { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* Card */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 13px; font-weight: 600;
  color: var(--text2); text-transform: uppercase; letter-spacing: .05em;
}
.card-body { padding: 16px 18px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text3);
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap; font-weight: 500;
}
tbody td {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px; vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface); }

/* Filters bar */
.filters-bar {
  display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap;
}
.filters-bar input,
.filters-bar select {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--r2); color: var(--text);
  padding: 7px 11px; font-size: 13px; outline: none;
  transition: border-color .15s;
}
.filters-bar input { flex: 1; min-width: 160px; }
.filters-bar input:focus,
.filters-bar select:focus { border-color: var(--accent); }
.filters-bar select option { background: var(--bg2); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--r2);
  font-size: 13px; font-weight: 500; border: none;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent2); }
.btn-secondary {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border2);
}
.btn-secondary:hover { background: var(--surface); color: var(--text); }
.btn-danger   { background: var(--red-bg); color: var(--red); border: 1px solid rgba(248,81,73,.3); }
.btn-danger:hover { background: rgba(248,81,73,.2); }
.btn-success  { background: var(--green-bg); color: var(--green); border: 1px solid rgba(63,185,80,.3); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Forms */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.cols1 { grid-template-columns: 1fr; }
.form-grid.cols3 { grid-template-columns: 1fr 1fr 1fr; }
.span2 { grid-column: span 2; }
label { font-size: 12px; font-weight: 500; color: var(--text2); }
.req  { color: var(--red); margin-left: 2px; }
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], select, textarea {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--r2); color: var(--text);
  padding: 8px 11px; font-size: 13px; outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56,139,253,.15);
}
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--bg2); }

/* Toggle */
.toggle-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--surface2); border-radius: 20px; cursor: pointer;
  transition: background .2s;
}
.toggle-slider:before {
  content: ''; position: absolute;
  width: 14px; height: 14px; left: 3px; top: 3px;
  background: var(--text2); border-radius: 50%; transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(16px); background: #fff; }
.toggle-label { font-size: 13px; color: var(--text); }

/* Pills / Badges */
.pill {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.pill-pending   { background: var(--surface2);   color: var(--text2); }
.pill-progress  { background: var(--accent-bg);  color: var(--accent); }
.pill-review    { background: var(--purple-bg);  color: var(--purple); }
.pill-completed { background: var(--green-bg);   color: var(--green); }
.pill-cancelled { background: var(--red-bg);     color: var(--red); }
.pill-overdue   { background: var(--red-bg);     color: var(--red); }
.pill-monthly   { background: var(--accent-bg);  color: var(--accent); }
.pill-annual    { background: var(--purple-bg);  color: var(--purple); }
.pill-active    { background: var(--green-bg);   color: var(--green); }
.pill-inactive  { background: var(--surface2);   color: var(--text2); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-urgent { background: var(--red); }
.dot-high   { background: var(--amber); }
.dot-normal { background: var(--accent); }
.dot-low    { background: var(--text3); }

/* Alerts */
.alert {
  padding: 10px 14px; border-radius: var(--r2);
  font-size: 13px; margin-bottom: 14px;
}
.alert-danger  { background: var(--red-bg);   color: var(--red);   border: 1px solid rgba(248,81,73,.3); }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(63,185,80,.3); }
.alert-info    { background: var(--accent-bg);color: var(--accent);border: 1px solid rgba(56,139,253,.3); }

/* Empty state */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text3);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-text { font-size: 14px; color: var(--text2); margin-bottom: 6px; }
.empty-sub  { font-size: 12px; }

/* Loading */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 48px; color: var(--text2);
  gap: 10px; font-size: 13px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow2);
}
.modal.modal-wide {
  max-width: min(1180px, calc(100vw - 40px));
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title  { font-size: 16px; font-weight: 600; }
.modal-close  {
  background: none; border: none; color: var(--text2);
  font-size: 18px; padding: 2px 6px; border-radius: 4px;
  transition: background .12s, color .12s;
}
.modal-close:hover { background: var(--surface); color: var(--text); }
.modal-body   { padding: 20px; overflow-y: auto; }
.modal-wide .modal-body { overflow-x: hidden; }
.modal-wide .table-wrap { overflow-x: visible; }
.modal-wide table { table-layout: auto; }
.modal-wide td:last-child,
.modal-wide th:last-child {
  min-width: 210px;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .modal-wide .table-wrap { overflow-x: auto; }
}
.overdue-notice-table table { table-layout: fixed; }
.overdue-notice-table th:nth-child(1),
.overdue-notice-table td:nth-child(1) { width: 22%; }
.overdue-notice-table th:nth-child(2),
.overdue-notice-table td:nth-child(2) { width: 14%; }
.overdue-notice-table th:nth-child(3),
.overdue-notice-table td:nth-child(3) { width: 14%; }
.overdue-notice-table th:nth-child(4),
.overdue-notice-table td:nth-child(4) { width: 10%; }
.overdue-notice-table th:nth-child(5),
.overdue-notice-table td:nth-child(5) { width: 12%; }
.overdue-notice-table th:nth-child(6),
.overdue-notice-table td:nth-child(6) { width: 28%; }
.overdue-notice-table td {
  overflow-wrap: anywhere;
}

/* Toast */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 2000;
}
.toast {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--r2); padding: 12px 16px;
  font-size: 13px; box-shadow: var(--shadow2);
  display: flex; align-items: center; gap: 10px;
  animation: slideIn .2s ease;
  max-width: 320px;
}
.toast.success { border-color: rgba(63,185,80,.4); }
.toast.error   { border-color: rgba(248,81,73,.4); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Progress bar */
.progress { background: var(--surface2); border-radius: 4px; height: 6px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 4px; transition: width .3s; }
.progress-bar.green  { background: var(--green); }
.progress-bar.amber  { background: var(--amber); }
.progress-bar.red    { background: var(--red); }
.progress-bar.accent { background: var(--accent); }

/* Divider */
hr.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* Avatar stack */
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -6px; border: 2px solid var(--bg2); width: 26px; height: 26px; font-size: 10px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* Workload bar */
.workload-item { margin-bottom: 14px; }
.workload-header { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.workload-name { color: var(--text); }
.workload-count { color: var(--text2); font-family: 'DM Mono', monospace; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
  .page { padding: 16px; }
}
