:root {
  --bg: #0f1420;
  --panel: #161d2e;
  --panel-border: #232c42;
  --text: #e7ebf3;
  --muted: #8a93a8;
  --primary: #5b8def;
  --primary-dark: #3f6fd1;
  --danger: #eb5757;
  --good: #27ae60;
  --warn: #f2994a;
  --radius: 10px;
  /* Tells the browser to render native form controls (date-picker calendar icon,
     select dropdown arrows, checkboxes) in a style that suits a dark background —
     without this, the calendar icon on <input type="date"> can render as
     near-invisible dark-on-dark. */
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }

.muted { color: var(--muted); font-size: 0.9em; }
code { background: #0d1220; border: 1px solid var(--panel-border); border-radius: 4px; padding: 1px 5px; font-size: 0.85em; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { font-size: 1.3em; margin: 0 0 4px; }

label { display: block; margin: 14px 0 6px; font-size: 0.85em; color: var(--muted); }
input, textarea, select {
  width: 100%;
  padding: 9px 11px;
  background: #0d1220;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95em;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: 1px solid var(--primary); }
/* Belt-and-suspenders for the calendar icon on Chrome/Edge, in case color-scheme
   isn't picked up (older browsers, some OS themes). */
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.85); cursor: pointer; }

.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #263252; color: var(--text); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--panel-border); }
.btn-danger { background: var(--danger); color: white; }
.btn-small { padding: 4px 10px; font-size: 0.8em; }
.btn-block { width: 100%; margin-top: 18px; }

/* Shell */
.shell { min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
}
.brand { font-weight: 700; }
.nav { display: flex; gap: 18px; flex: 1; }
.nav a { color: var(--muted); padding: 6px 4px; border-bottom: 2px solid transparent; }
.nav a.active, .nav a:hover { color: var(--text); border-color: var(--primary); }
.user-menu { display: flex; align-items: center; gap: 12px; }
.role-badge { font-size: 0.7em; padding: 2px 7px; border-radius: 20px; background: #263252; margin-left: 6px; text-transform: uppercase; }

.view { padding: 24px; max-width: 1200px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel h3 { margin-top: 0; }
.panel-narrow { max-width: 480px; }

.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius); padding: 18px; text-align: center; }
.stat-value { font-size: 2em; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85em; margin-top: 4px; }
.stat-danger .stat-value { color: var(--danger); }
.stat-good .stat-value { color: var(--good); }

.charts-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 20px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td, .mini-table th, .mini-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--panel-border);
  font-size: 0.9em;
}
.data-table th, .mini-table th { color: var(--muted); font-weight: 600; font-size: 0.78em; text-transform: uppercase; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #1c2438; }
tr.row-overdue td:first-child { border-left: 3px solid var(--danger); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 0.75em; font-weight: 600; }
.sev-critical { background: rgba(235,87,87,0.2); color: #ff8a8a; }
.sev-high { background: rgba(242,153,74,0.2); color: #ffb877; }
.sev-medium { background: rgba(91,141,239,0.2); color: #8fb3ff; }
.sev-low { background: rgba(39,174,96,0.2); color: #6fe19c; }
.st-open { background: #263252; color: #b9c6e5; }
.st-in_progress { background: rgba(91,141,239,0.2); color: #8fb3ff; }
.st-in_review { background: rgba(242,153,74,0.2); color: #ffb877; }
.st-resolved { background: rgba(39,174,96,0.2); color: #6fe19c; }
.st-closed { background: #1e2536; color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.filters input, .filters select { width: auto; min-width: 140px; }
.filters-spacer { flex: 1 1 auto; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 0.85em; color: var(--muted); }
.checkbox-label input { width: auto; }

.bulk-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: rgba(88,166,255,0.1);
  border: 1px solid rgba(88,166,255,0.3);
  border-radius: 8px;
}
.bulk-toolbar select { width: auto; min-width: 140px; }
.bulk-toolbar .bulk-count { font-weight: 600; margin-right: 6px; }
.bulk-toolbar .error-box { flex-basis: 100%; margin: 0; }
.bulk-toolbar.hidden { display: none; }
.data-table th input[type="checkbox"], .data-table td input[type="checkbox"] { width: auto; margin: 0; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }

.error-box { background: rgba(235,87,87,0.15); border: 1px solid rgba(235,87,87,0.4); color: #ff9a9a; padding: 10px 12px; border-radius: 8px; margin-top: 12px; }
.hidden { display: none; }

.task-header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-header h2 { margin: 0; }
.readonly select, .readonly textarea, .readonly input { opacity: 0.75; }

.attachment-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--panel-border); }
.attachment-row:last-child { border-bottom: none; }
.upload-form { display: flex; gap: 10px; margin-top: 14px; align-items: center; }
.upload-form input[type="file"] { width: auto; border: none; padding: 0; }

.comment { padding: 10px 0; border-bottom: 1px solid var(--panel-border); }
.comment-body { margin-top: 4px; white-space: pre-wrap; }
.comment-form { margin-top: 14px; display: flex; gap: 10px; align-items: flex-start; }
.comment-form textarea { flex: 1; }

.activity-list { display: flex; flex-direction: column; gap: 8px; }
.activity-row { font-size: 0.88em; display: flex; gap: 8px; flex-wrap: wrap; }

.loading { padding: 40px; text-align: center; color: var(--muted); }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--panel); border: 1px solid var(--panel-border);
  padding: 12px 18px; border-radius: 8px;
  opacity: 0; transform: translateY(10px);
  transition: all 0.25s ease;
  z-index: 1000;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-color: var(--danger); color: #ff9a9a; }
