/* Theme + UI Enhancements */
:root {
  --bg: #0f1115;
  --panel: #151923;
  --text: #e8eaf1;
  --muted: #9aa3b2;
  --primary: #2f6df6;
  --border: #243047;
  --radius: 12px;
}

[data-theme="light"] {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #51607a;
  --primary: #2f6df6;
  --border: #dde3ef;
}

* { box-sizing: border-box; }
body { margin:0; background: var(--bg); color: var(--text); font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
.container { width: min(1600px, 98%); margin: 0 auto; }
.row { display:flex; gap:10px; }
.center { align-items: center; }
.space-between { justify-content: space-between; }
.muted { color: var(--muted); }

.topbar { position: sticky; top:0; z-index:10; background:#0c101a; border-bottom: 1px solid var(--border); }
[data-theme="light"] .topbar { background: #ffffff; }
.brand { display:inline-flex; gap:10px; align-items:center; text-decoration:none; color:var(--text); }
.brand .brand-text { font-weight:700; }
.nav a { color: var(--muted); text-decoration:none; margin:0 8px; padding:8px 10px; border-radius:8px; }
.nav a:hover { color: var(--text); background:#131826; }
.theme-toggle { margin-left: 8px; background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.theme-toggle:hover { color: var(--text); }
.theme-toggle { margin-left: 8px; background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.theme-toggle:hover { color: var(--text); }
.user { display:flex; gap:10px; align-items:center; }
.user .user-name { color:var(--muted); font-size:14px; }

main.container { padding:24px 0 56px; }
/* Slightly more compact layout on CAD page */
[data-page="cad"] main.container { padding-top:12px; padding-bottom:32px; }
.hero { padding: 48px 0 8px; }
.hero h1 { font-size: clamp(26px, 3.5vw, 36px); margin: 0 0 8px; }
.lead { color: var(--muted); margin: 0 0 18px; }
.cta { display:flex; gap:12px; }

.btn { display:inline-block; background:#1a2030; color:var(--text); border:1px solid var(--border); padding:10px 14px; border-radius:10px; text-decoration:none; font-weight:600; transition: background 120ms ease, box-shadow 120ms ease, transform 60ms ease; }
.btn:hover { background:#131826; }
.btn.primary { background: var(--primary); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { padding:6px 10px; font-size:14px; }

/* Light theme polish: nav hover and buttons */
[data-theme="light"] .nav a:hover { background:#eef2fb; }
[data-theme="light"] .theme-toggle { background:#ffffff; }
[data-theme="light"] .theme-toggle:hover { background:#f2f5fc; color: var(--text); }

[data-theme="light"] .btn {
  background: #ffffff;
  color: var(--text);
  border-color: var(--border);
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}
[data-theme="light"] .btn:hover { background: #f2f5fc; }
[data-theme="light"] .btn:active { transform: translateY(1px); }
[data-theme="light"] .btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 14px rgba(47,109,246,0.25), 0 2px 6px rgba(47,109,246,0.2);
}
[data-theme="light"] .btn.primary:hover { filter: brightness(1.07); box-shadow: 0 8px 18px rgba(47,109,246,0.3), 0 3px 8px rgba(47,109,246,0.22); }
[data-theme="light"] .btn.primary:active { transform: translateY(1px); }

[data-page="cad"] .card { margin:6px; }
.card { background:#111622; border:1px solid var(--border); border-radius: var(--radius); padding:10px; margin:6px; }
[data-theme="light"] .card { background: var(--panel); }
.card { box-shadow: 0 1px 0 rgba(0,0,0,0.05); }
[data-theme="light"] .card { box-shadow: 0 6px 20px rgba(23,32,51,0.06), 0 2px 8px rgba(23,32,51,0.05); }
.placeholder { padding: 24px; background: #101523; border: 1px dashed #2a3550; border-radius: 10px; color: var(--muted); }
[data-theme="light"] .placeholder { background: #f9fafe; border-color: #d1d9e8; }
.alert { padding: 12px 14px; border-radius: 10px; background: rgba(230,69,83,0.1); border: 1px solid rgba(230,69,83,0.3); }

.footer { padding:24px 0; display:flex; justify-content:space-between; align-items:center; border-top:1px solid var(--border); color:var(--muted); font-size:14px; }

/* Forms */
input[type="text"], input[type="email"], input[type="password"], input[type="date"], textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1422;
  color: var(--text);
}
[disabled], input[readonly] {
  opacity: 0.6;
  cursor: not-allowed;
  background: #0b0e14;
}
[data-theme="light"] [disabled], [data-theme="light"] input[readonly] {
  opacity: 0.8;
}
[data-theme="light"] input[type="text"], [data-theme="light"] input[type="email"], [data-theme="light"] input[type="password"], [data-theme="light"] input[type="date"], [data-theme="light"] textarea { background: #fff; }
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus, input[type="date"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47,109,246,0.2);
}
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1422;
  color: var(--text);
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) calc(1em + 2px), calc(100% - 15px) calc(1em + 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
[data-theme="light"] select { background: #fff; }
label { color: var(--text); font-weight: 600; display: block; }
label input, label textarea { margin-top: 6px; font-weight: 400; }

/* Settings tabs */
.tabs { display:flex; gap:8px; margin: 8px 0 12px; }
.tab { background:#1a2030; color:var(--muted); border:1px solid var(--border); border-radius:8px; padding:8px 12px; cursor:pointer; transition: background 120ms ease, color 120ms ease; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background:#131826; }
[data-theme="light"] .tab { background:#ffffff; }
[data-theme="light"] .tab.active { background:#eef2fb; color:#172033; border-color:#cfd8ea; }
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.tab-content { display:none; }
.tab-content.active { display:block; }
.form-grid label.stack { display:block; margin-bottom: 12px; }
.form-grid label.stack span { display:block; margin-bottom: 6px; color: var(--muted); font-weight: 600; }

/* Comments box - theme aware and looks like a textarea */
.comments-box {
  max-height: 260px;
  overflow: auto;
  margin-bottom: 8px;
  resize: vertical;
  min-height: 80px;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 8px;
  /* match text input background so date input looks consistent with other inputs */
  background: #0f1422;
  color: var(--text);
}
.comments-box:focus { outline: none; box-shadow: 0 0 0 3px rgba(47,109,246,0.12); }
.comments-box table { width:100%; border-collapse: collapse; }
.comments-box table tr { border-bottom: 1px solid rgba(255,255,255,0.03); }
.comments-box td { padding: 6px; vertical-align: top; }
/* Allow the main comment content to wrap */
.comments-box td:first-child { white-space: normal; word-break: break-word; }
/* Keep author and time tightly sized and right-aligned on the far right */
.comments-box td:nth-child(2), .comments-box td:nth-child(3) {
  white-space: nowrap;
  width: 1%; /* small intrinsic width so it only takes what's needed */
  text-align: right;
  padding-left: 10px;
  font-size:12px;
  color: var(--muted)
}

[data-theme="light"] .comments-box { background: #fff; border-color: var(--border); }
[data-theme="light"] .comments-box table tr { border-bottom: 1px solid rgba(0,0,0,0.04); }

/* Incidents table */
#incidents-table { width: 100%; }
#incidents-table td, #incidents-table th { padding: 6px 8px; }
#incidents-table td:nth-child(3) { white-space: normal; word-break: break-word; }
#incidents-table tbody tr:hover { background: rgba(47,109,246,0.04); }
#incidents-table tbody tr { transition: background 120ms ease; }

/* Make incidents list scrollable to avoid page vertical scroll on CAD */
#incidents-card { max-height: calc(80vh); overflow: auto; min-width:320px; overflow-x: auto; min-height: calc(80vh); }
#incidents-card table { font-size: 13px; }
#incidents-card table { min-width: 720px; }
#incidents-card td, #incidents-card th { white-space: nowrap; }
#incidents-card .grade-col { width: 80px; }
#incidents-card .status-col { width: 120px; }
/* Units card placed under the open log card */
#units-card { max-height: calc(80vh); overflow: auto; min-height: calc(80vh); }
[data-page="cad"] #units-card { margin-left: 0; }
#open-card { max-height: calc(80vh); overflow-x: auto; min-height: calc(80vh); }

/* Ensure date inputs (DOB) visually match text inputs */
#informant_dob {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1422;
  color: var(--text);
  box-sizing: border-box;
  appearance: textfield;
}
#informant_dob:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47,109,246,0.2);
}
[data-theme="light"] #informant_dob { background: #fff; }
