:root {
  --bg: #0a0e17;
  --bg-grid: #0d1220;
  --panel: #121927;
  --panel-2: #16203400;
  --panel-raised: #182238;
  --border: #232d45;
  --border-soft: #1a2338;
  --text: #e8edf7;
  --muted: #8b96ae;
  --muted-2: #5c6885;
  --accent: #3da5ff;
  --accent-dim: #1c4a75;
  --amber: #ffb020;
  --amber-dim: #4a3413;
  --green: #33d6a6;
  --green-dim: #113d33;
  --red: #ff5a6e;
  --red-dim: #401820;
  --mono: ui-monospace, "SFMono-Regular", "IBM Plex Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, #14203a55, transparent),
    radial-gradient(900px 500px at 100% 0%, #0f2a2455, transparent),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, #0d1322, #0a0e17);
  position: sticky; top: 0; z-index: 20;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--accent-dim), #0d2036);
  border: 1px solid #2a5c8c;
  color: var(--accent);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-title { font-weight: 700; font-size: 15.5px; letter-spacing: 0.2px; }
.brand-sub { font-family: var(--mono); font-size: 11px; color: var(--muted-2); letter-spacing: 0.4px; text-transform: uppercase; }
.topbar-clock {
  font-family: var(--mono); font-size: 13px; color: var(--green);
  background: var(--green-dim); border: 1px solid #1c5c48;
  padding: 6px 12px; border-radius: 7px; letter-spacing: 1px;
}

/* ---------- Layout ---------- */
.body-row { display: flex; flex: 1; min-height: 0; }

.sidenav {
  width: 220px; flex-shrink: 0;
  padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--border-soft);
  background: #0b1120;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px; border-radius: 9px;
  background: transparent; border: 1px solid transparent;
  color: var(--muted); font-size: 14px; font-weight: 600;
  cursor: pointer; text-align: left; font-family: var(--sans);
  transition: background .15s, color .15s, border-color .15s;
}
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-item:hover { background: var(--panel-raised); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, var(--accent-dim), transparent);
  color: var(--accent); border-color: #1f4266;
}

.content { flex: 1; min-width: 0; padding: 22px 26px 60px; overflow-y: auto; }

/* ---------- Dashboard ---------- */
.view-title { display:flex; align-items:baseline; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.view-title h2 { margin: 0; font-size: 20px; letter-spacing: 0.2px; }
.view-title .hint { color: var(--muted-2); font-size: 12.5px; font-family: var(--mono); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 6px;
}
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-family: var(--mono); font-size: 30px; font-weight: 600; }
.stat-sub { font-size: 12px; color: var(--muted-2); }
.stat-sub.warn { color: var(--amber); }

.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.module-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px; cursor: pointer;
  display: flex; flex-direction: column; gap: 12px;
  transition: transform .12s, border-color .12s, background .12s;
  position: relative; overflow: hidden;
}
.module-card:hover { transform: translateY(-2px); border-color: #2b3c5c; background: var(--panel-raised); }
.module-card .icon-wrap {
  width: 46px; height: 46px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-dim); color: var(--accent);
}
.module-card .icon-wrap svg { width: 24px; height: 24px; }
.module-card h4 { margin: 0; font-size: 15.5px; }
.module-card p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.module-card .count-badge {
  position: absolute; top: 16px; right: 16px;
  font-family: var(--mono); font-size: 12px; color: var(--muted-2);
}

/* ---------- Toolbar / table ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.search-box {
  flex: 1; min-width: 180px; display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px;
}
.search-box svg { width: 16px; height: 16px; color: var(--muted-2); flex-shrink: 0; }
.search-box input { background: transparent; border: none; outline: none; color: var(--text); font-size: 13.5px; width: 100%; }
.btn {
  border: 1px solid var(--border); background: var(--panel-raised); color: var(--text);
  padding: 9px 16px; border-radius: 8px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  transition: background .15s, border-color .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: #1c2740; }
.btn-primary { background: linear-gradient(180deg, #4bb0ff, var(--accent)); color: #06172a; border-color: #4bb0ff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-danger { color: var(--red); }
.btn-ghost { background: transparent; }

.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13.2px; }
thead th {
  text-align: left; padding: 11px 14px; background: #0e1425;
  color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #101828; }
td.wrap { max-width: 260px; white-space: normal; color: var(--muted); }
td.actions { white-space: nowrap; text-align: right; }
.row-id { font-family: var(--mono); color: var(--muted-2); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; text-transform: capitalize; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.pending { color: var(--amber); background: var(--amber-dim); }
.pill.done { color: var(--green); background: var(--green-dim); }
.pill.other { color: var(--accent); background: var(--accent-dim); }

.thumb-btn { width: 34px; height: 34px; border-radius: 7px; overflow: hidden; border: 1px solid var(--border); cursor: pointer; background: var(--panel-raised); display: inline-flex; align-items: center; justify-content: center; color: var(--muted-2); }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; }

.icon-btn { width: 32px; height: 32px; border-radius: 7px; border: 1px solid var(--border); background: var(--panel-raised); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { color: var(--text); background: #1c2740; }
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn.danger:hover { color: var(--red); border-color: #6d2430; }

.empty-state { padding: 50px 20px; text-align: center; color: var(--muted-2); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 10px; opacity: 0.5; }

/* ---------- Modal / form ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(4,7,14,0.72); backdrop-filter: blur(2px); display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 100; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  background: #0d1424; border: 1px solid var(--border); border-radius: 7px;
  padding: 9px 11px; color: var(--text); font-size: 13.5px; font-family: var(--sans); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 60px; }

.photo-field { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.photo-preview { width: 84px; height: 84px; border-radius: 9px; border: 1px dashed var(--border); background: #0d1424; display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--muted-2); flex-shrink: 0; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-hint { font-size: 11.5px; color: var(--muted-2); width: 100%; }
.ocr-status { width: 100%; font-size: 12px; padding: 8px 11px; border-radius: 7px; display: none; }
.ocr-status.busy { display: block; color: var(--accent); background: var(--accent-dim); }
.ocr-status.ok { display: block; color: var(--green); background: var(--green-dim); }
.ocr-status.error { display: block; color: var(--red); background: var(--red-dim); }

/* ---------- Tickets ---------- */
.ticket-row { cursor: pointer; }
.priority-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.priority-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.priority-pill.priority-low { color: var(--muted); background: #1c2740; }
.priority-pill.priority-medium { color: var(--accent); background: var(--accent-dim); }
.priority-pill.priority-high { color: var(--amber); background: var(--amber-dim); }
.priority-pill.priority-urgent { color: var(--red); background: var(--red-dim); }

.modal.ticket-modal-size { max-width: 680px; }
.static-val { padding: 9px 11px; background: #0d1424; border: 1px solid var(--border-soft); border-radius: 7px; font-size: 13.5px; color: var(--text); min-height: 18px; }

.comments-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border-soft); }
.comments-section h4 { margin: 0 0 12px; font-size: 14px; }
.comments-list { display: flex; flex-direction: column; gap: 10px; max-height: 260px; overflow-y: auto; margin-bottom: 12px; }
.comment { background: #0d1424; border: 1px solid var(--border-soft); border-radius: 9px; padding: 10px 12px; }
.comment-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.comment-author { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.comment-time { font-size: 11px; color: var(--muted-2); font-family: var(--mono); }
.comment-msg { font-size: 13px; color: var(--text); white-space: pre-wrap; line-height: 1.5; }
.comment-box { display: flex; gap: 8px; align-items: flex-end; }
.comment-box textarea { flex: 1; min-height: 44px; background: #0d1424; border: 1px solid var(--border); border-radius: 7px; padding: 9px 11px; color: var(--text); font-family: var(--sans); font-size: 13.5px; resize: vertical; }
.comment-box .btn { flex-shrink: 0; }

/* ---------- Document type filter & pills ---------- */
.type-filter {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; color: var(--text); font-size: 13.5px; font-family: var(--sans);
  cursor: pointer;
}
.pill.type-circular { color: #b28aff; background: #2a1d4a; }
.pill.type-office-order { color: var(--accent); background: var(--accent-dim); }
.pill.type-notification { color: var(--amber); background: var(--amber-dim); }
.pill.type-gate-pass { color: var(--green); background: var(--green-dim); }
.pill.type-general { color: var(--muted); background: #1c2740; }

.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border-soft); }

.photo-modal { max-width: 720px; }
.photo-body { padding: 12px; display: flex; align-items: center; justify-content: center; background: #05070d; }
.photo-body img { max-width: 100%; max-height: 74vh; border-radius: 6px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--panel-raised); border: 1px solid var(--border); color: var(--text); padding: 11px 20px; border-radius: 9px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,0.4); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: #6d2430; color: var(--red); }

/* ---------- Login screen ---------- */
.login-screen {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 600px at 15% -10%, #14203a66, transparent),
    radial-gradient(900px 500px at 100% 10%, #0f2a2466, transparent),
    var(--bg);
  padding: 20px; z-index: 500;
}
.login-screen.open { display: flex; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 30px 28px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-card h2 { margin: 0 0 18px; font-size: 18px; }
.login-card .field { margin-bottom: 14px; }
.login-btn { width: 100%; justify-content: center; margin-top: 6px; padding: 11px; font-size: 14px; }
.login-error { color: var(--red); font-size: 12.5px; min-height: 16px; margin-bottom: 4px; }

/* ---------- User chip (topbar) ---------- */
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 9px; background: var(--panel-raised); border: 1px solid var(--border); border-radius: 30px; padding: 5px 8px 5px 5px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-dim); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 700; font-family: var(--mono); text-transform: uppercase; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-size: 12.5px; font-weight: 700; }
.user-role { font-size: 10px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.4px; }

/* ---------- Users admin panel ---------- */
.role-pill { display: inline-flex; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; text-transform: capitalize; }
.role-pill.admin { color: var(--red); background: var(--red-dim); }
.role-pill.superadmin { color: #1a1a1a; background: linear-gradient(135deg, #ffd66b, #f5a623); }
.role-pill.user { color: var(--accent); background: var(--accent-dim); }
.role-pill.guest { color: var(--muted); background: #1c2740; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.status-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.status-dot.inactive::before { background: var(--muted-2); }
.status-dot.inactive { color: var(--muted-2); }

@media (max-width: 760px) {
  .topbar-right { gap: 8px; }
  .user-meta { display: none; }
  .user-chip { padding: 4px; border-radius: 50%; }
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .module-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .topbar { padding: 12px 14px; }
  .brand-sub { display: none; }
  .content { padding: 16px 14px 90px; }
  .body-row { flex-direction: column-reverse; }
  .sidenav {
    width: 100%; flex-direction: row; justify-content: space-around;
    border-right: none; border-top: 1px solid var(--border-soft);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    padding: 8px 4px; background: #0a0e19ee; backdrop-filter: blur(6px);
  }
  .nav-item { flex-direction: column; gap: 4px; padding: 7px 6px; font-size: 10.5px; flex: 1; }
  .nav-item span { white-space: nowrap; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 24px; }
  .module-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  table { font-size: 12.5px; }
  thead { display: none; }
  tbody tr { display: block; border-bottom: 6px solid var(--bg); }
  tbody td { display: flex; justify-content: space-between; gap: 10px; text-align: right; border-bottom: 1px dashed var(--border-soft); }
  tbody td::before { content: attr(data-label); color: var(--muted-2); font-weight: 600; text-align: left; font-size: 11px; text-transform: uppercase; }
  tbody td.actions { justify-content: flex-end; }
  tbody td.actions::before { content: none; }
  .table-wrap { border: none; background: none; }
  tbody tr { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; display: block; padding: 4px 0; margin-bottom: 10px; }
}
