/* ═══════════════════════════════════════════════════════════════
   MSCON DESIGN – Operations Platform
   Bold professional UI with switchable colour themes
   ═══════════════════════════════════════════════════════════════ */

/* ── Colour Themes ────────────────────────────────────────────── */

/* Theme 1: Teal & Navy (default) — popular with engineers */
:root,
[data-theme="teal"] {
  --sidebar-bg:   #0d1b2a;
  --sidebar-hi:   #1a3045;
  --sidebar-txt:  #c8d9e8;
  --sidebar-act:  #ffffff;
  --primary:      #00b4a0;
  --primary-dk:   #007f70;
  --accent:       #2563eb;
  --ink:          #0f1923;
  --muted:        #5e7486;
  --line:         #d8e4ed;
  --surface:      #f0f4f8;
  --panel:        #ffffff;
  --danger:       #c0392b;
  --warn:         #d97706;
  --good:         #059669;
  --badge-pend:   #fff3cd;
  --badge-pend-t: #856404;
}

/* Theme 2: Indigo & Gold — architect / premium feel */
[data-theme="indigo"] {
  --sidebar-bg:   #1a1040;
  --sidebar-hi:   #2d1f6e;
  --sidebar-txt:  #c5bff0;
  --sidebar-act:  #ffd700;
  --primary:      #6c47ff;
  --primary-dk:   #4f2ee8;
  --accent:       #f59e0b;
  --ink:          #1a1040;
  --muted:        #64748b;
  --line:         #e2e8f0;
  --surface:      #f5f3ff;
  --panel:        #ffffff;
  --danger:       #dc2626;
  --warn:         #d97706;
  --good:         #059669;
  --badge-pend:   #fff7ed;
  --badge-pend-t: #92400e;
}

/* Theme 3: Slate & Ember — dark-mode-adjacent, popular with devs */
[data-theme="slate"] {
  --sidebar-bg:   #1e293b;
  --sidebar-hi:   #334155;
  --sidebar-txt:  #94a3b8;
  --sidebar-act:  #fb923c;
  --primary:      #f97316;
  --primary-dk:   #ea580c;
  --accent:       #38bdf8;
  --ink:          #1e293b;
  --muted:        #64748b;
  --line:         #e2e8f0;
  --surface:      #f1f5f9;
  --panel:        #ffffff;
  --danger:       #ef4444;
  --warn:         #f59e0b;
  --good:         #22c55e;
  --badge-pend:   #fef9c3;
  --badge-pend-t: #854d0e;
}

/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  background: var(--surface);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* ── Login Screen ─────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--sidebar-bg) 0%, #0a2540 100%);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border-radius: 16px;
  padding: 32px;
  display: grid;
  gap: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}

/* ── App Shell ────────────────────────────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px 1fr;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-txt);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand.compact { color: var(--ink); }

.brand-mark {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dk));
  color: #fff;
  font-weight: 800;
  font-size: 1.25rem;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

.brand h1 { margin: 0; font-size: 1rem; font-weight: 700; color: #fff; }
.brand p { margin: 0; font-size: .75rem; color: var(--sidebar-txt); opacity: .7; }

.nav { display: grid; gap: 2px; }

.nav-item {
  border: 0;
  background: transparent;
  color: var(--sidebar-txt);
  padding: 10px 14px;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  position: relative;
}

.nav-item::before {
  content: '';
  position: absolute;
  left: 0; top: 25%; bottom: 25%;
  width: 3px;
  border-radius: 999px;
  background: var(--primary);
  opacity: 0;
  transition: opacity .15s;
}

.nav-item.active {
  background: var(--sidebar-hi);
  color: var(--sidebar-act);
  font-weight: 600;
}

.nav-item.active::before { opacity: 1; }

.nav-item:hover:not(.active) {
  background: rgba(255,255,255,.06);
  color: #fff;
}

.tenant-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  display: grid;
  gap: 6px;
}

.tenant-card strong { color: #fff; font-size: .9rem; }
.tenant-card span { font-size: .75rem; color: var(--primary); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }

.ghost-btn {
  border: 0;
  background: transparent;
  color: var(--sidebar-txt);
  padding: 6px 0;
  cursor: pointer;
  font-size: .8rem;
  text-align: left;
  transition: color .15s;
}
.ghost-btn:hover { color: #fff; }

/* ── Theme Switcher (sidebar) ─────────────────────────────────── */
.theme-switcher {
  display: flex;
  gap: 6px;
  padding: 0 8px;
  margin-top: -8px;
}
.theme-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.theme-dot:hover, .theme-dot.active { transform: scale(1.2); border-color: #fff; }
.theme-dot.t-teal   { background: #00b4a0; }
.theme-dot.t-indigo { background: #6c47ff; }
.theme-dot.t-slate  { background: #f97316; }

/* ── Main Content ─────────────────────────────────────────────── */
.main { padding: 24px; min-width: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--line);
}

.eyebrow {
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .08em;
  margin: 0;
}

#viewTitle {
  margin: 4px 0 0;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--ink);
}

/* ── Metrics ──────────────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  display: grid;
  gap: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  position: relative;
  overflow: hidden;
}

.metric::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-dk));
  opacity: 0;
  transition: opacity .2s;
}
.metric:hover::after { opacity: 1; }

.metric span { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.metric strong { font-size: 2.2rem; font-weight: 800; color: var(--ink); }
.metric.warning strong { color: var(--warn); }

/* ── Panels & Cards ───────────────────────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.split-layout    { display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 20px; }
.form-grid       { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: 1 / -1; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.stack-list { display: grid; gap: 10px; }

/* ── Items / Cards ────────────────────────────────────────────── */
.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  display: grid;
  gap: 8px;
  background: var(--panel);
  transition: box-shadow .15s, border-color .15s;
}
.item:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); border-color: var(--primary); }
.item-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.item-row strong { font-weight: 600; }

/* ── Pills / Badges ───────────────────────────────────────────── */
.pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 10px;
  background: #e8f0fe;
  color: #1a3a6e;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.pill.delayed { background: #fce8e6; color: #8f2013; }
.pill.good    { background: #d7f5e9; color: #0a5c36; }
.pill.muted   { background: #f1f5f9; color: #64748b; }

/* ── Buttons ──────────────────────────────────────────────────── */
.primary-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-dk));
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  font-weight: 700;
  font-size: .9rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  transition: opacity .15s, transform .1s;
}
.primary-btn:hover { opacity: .92; transform: translateY(-1px); }
.primary-btn:active { transform: translateY(0); }

.secondary-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  font-weight: 700;
  font-size: .9rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  transition: opacity .15s;
}
.secondary-btn:hover { opacity: .9; }

.mini-btn {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: .8rem;
  transition: background .12s, border-color .12s;
}
.mini-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Forms ────────────────────────────────────────────────────── */
label { display: grid; gap: 5px; color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

input, select {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 10px 13px;
  background: #fff;
  color: var(--ink);
  font-size: .9rem;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 180, 160, .12);
}

fieldset {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0;
  padding: 14px;
}
fieldset label { display: flex; align-items: center; gap: 6px; text-transform: none; letter-spacing: 0; font-weight: 500; font-size: .875rem; color: var(--ink); }
legend { font-weight: 700; color: var(--ink); font-size: .85rem; padding: 0 6px; }

/* ── Tables ───────────────────────────────────────────────────── */
.task-table { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); }
table { width: 100%; min-width: 960px; border-collapse: collapse; }
thead { background: var(--surface); }
th { padding: 12px 14px; text-align: left; font-size: .75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid var(--line); }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--surface); }

/* ── View transitions ─────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; animation: fadeSlide .22s ease; }

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.wide { grid-column: 1 / -1; }

/* ── Misc ─────────────────────────────────────────────────────── */
.muted { color: var(--muted); font-size: .85rem; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-message { min-height: 20px; margin-bottom: 12px; }
.error-text { color: var(--danger) !important; font-weight: 700; }

/* ── Admin tabs ───────────────────────────────────────────────── */
.tab-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab-pill {
  padding: 6px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  transition: all .15s;
}
.tab-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: 0 2px 8px rgba(0,180,160,.25); }
.tab-pill:hover:not(.active) { border-color: var(--primary); color: var(--primary); }
.admin-tab-panel { display: none; }
.admin-tab-panel.active-tab { display: block; }

/* ── AI Chat ──────────────────────────────────────────────────── */
.chat-area { display: flex; flex-direction: column; gap: .6rem; padding: .75rem; min-height: 280px; max-height: 420px; overflow-y: auto; background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px; }
.chat-bubble { max-width: 80%; padding: .6rem .85rem; border-radius: 14px; font-size: .875rem; line-height: 1.5; }
.chat-bubble.user { align-self: flex-end; background: linear-gradient(135deg, var(--primary), var(--primary-dk)); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble.ai { align-self: flex-start; background: #fff; border: 1.5px solid var(--line); border-bottom-left-radius: 4px; }
.chat-bubble.ai.thinking { color: var(--muted); font-style: italic; }
.chat-input-row { display: flex; gap: .5rem; align-items: center; }
.chat-input-row input { flex: 1; }

/* ── Performance ──────────────────────────────────────────────── */
.score-bar-wrap { background: #e9ecef; border-radius: .25rem; height: 8px; margin-top: .25rem; }
.score-bar { height: 8px; border-radius: .25rem; transition: width .5s cubic-bezier(.4,0,.2,1); }
.score-bar.green  { background: linear-gradient(90deg, var(--good), #34d399); }
.score-bar.yellow { background: linear-gradient(90deg, var(--warn), #fbbf24); }
.score-bar.red    { background: linear-gradient(90deg, var(--danger), #f87171); }
.score-ring { width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.1rem; color: #fff; margin-right: .75rem; flex-shrink: 0; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.perf-card { display: flex; align-items: flex-start; gap: .75rem; padding: .75rem; border-bottom: 1px solid var(--line); }
.perf-card:last-child { border-bottom: none; }
.perf-meta { flex: 1; }
.perf-narrative { font-size: .8rem; color: var(--muted); margin-top: .35rem; line-height: 1.5; }

/* ── Calendar / Attendance ────────────────────────────────────── */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; margin-top: .5rem; }
.cal-day { aspect-ratio: 1; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .65rem; background: #e9ecef; font-weight: 600; }
.cal-day.present { background: var(--good); color: #fff; }
.cal-day.absent  { background: var(--danger); color: #fff; }
.cal-day.half    { background: var(--warn); color: #fff; }

/* ── Geofence / Settings ──────────────────────────────────────── */
.fence-type-toggle { display: flex; gap: .5rem; margin-bottom: .5rem; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stat-row { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px solid var(--line); font-size: .875rem; }
.stat-row:last-child { border-bottom: none; }

/* ── Broadcast ────────────────────────────────────────────────── */
.broadcast-target { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.broadcast-target label { display: flex; align-items: center; gap: .3rem; font-size: .875rem; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink); }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app-shell            { grid-template-columns: 1fr; }
  .sidebar              { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
  .brand                { flex: 1; min-width: 160px; }
  .nav                  { flex-direction: row; flex: 100%; order: 3; overflow-x: auto; padding-bottom: 4px; }
  .nav-item             { white-space: nowrap; padding: 8px 12px; }
  .theme-switcher       { align-self: center; }
  .tenant-card          { flex-direction: row; align-items: center; flex: 100%; order: 4; margin-top: 0; grid-template-columns: auto 1fr auto auto; }
  .metric-grid          { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid,
  .split-layout,
  .form-grid            { grid-template-columns: 1fr; }
  fieldset              { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .main                 { padding: 12px; }
  .metric-grid          { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .metric strong        { font-size: 1.6rem; }
  .settings-grid        { grid-template-columns: 1fr; }
  fieldset              { grid-template-columns: 1fr; }
  table                 { min-width: 720px; }
  #viewTitle            { font-size: 1.2rem; }
}
