/*
 * CUAS Training Server - Admin & Report Styles
 *
 * ============================================================
 * COLOR CUSTOMIZATION
 * ============================================================
 * All colors are defined as CSS variables below. Change these
 * to match your organization's branding. Each variable is
 * documented with its purpose.
 *
 * To override per-page, add a <style> block in the HTML after
 * the stylesheet link:
 *   <style>:root { --bg-primary: #1a1a2e; }</style>
 * ============================================================
 */

:root {
  /* --- Page backgrounds --- */
  --bg-primary: #0d1117;         /* Main page background */
  --bg-secondary: #161b22;       /* Cards, header, panels */
  --bg-tertiary: #21262d;        /* Inputs, hover states, nested items */

  /* --- Borders --- */
  --border: #30363d;             /* All borders */

  /* --- Text --- */
  --text-primary: #e6edf3;       /* Main text color */
  --text-secondary: #8b949e;     /* Muted/label text */

  /* --- Accent / Brand --- */
  --accent: #58a6ff;             /* Links, headings, highlights */
  --accent-hover: #79c0ff;       /* Hover state for accent */

  /* --- Status colors --- */
  --success: #3fb950;            /* Success messages, green buttons */
  --danger: #f85149;             /* Error messages, delete buttons */
  --warning: #d29922;            /* Credential boxes, warnings */

  /* --- Badge colors --- */
  --badge-role-bg: #1f3a5f;      /* Role badge background */
  --badge-role-fg: #58a6ff;      /* Role badge text */
  --badge-session-bg: #2a1f3a;   /* Session badge background */
  --badge-session-fg: #bc8cff;   /* Session badge text */
  --badge-group-bg: #1f3a2a;     /* Group badge background */
  --badge-group-fg: #3fb950;     /* Group badge text */

  /* --- Leaderboard --- */
  --gold: #ffd700;               /* 1st place */
  --silver: #c0c0c0;             /* 2nd place */
  --bronze: #cd7f32;             /* 3rd place */

  /* --- Typography (Marine) --- */
  --font-heading: 'Copperplate Gothic Bold', 'Colossalis', 'Cinzel', Georgia, serif;
  --font-body: Arial, Helvetica, sans-serif;

  /* --- Layout --- */
  --radius: 6px;                 /* Border radius for all elements */

  /* --- Background image (set to a URL for custom background) --- */
  --bg-image: none;              /* e.g. url('/images/bg-pattern.png') */
  --bg-image-opacity: 0.06;      /* Opacity of background image overlay */

  /* --- Login page (can override per-page) --- */
  --login-bg-image: none;        /* e.g. url('/images/login-bg.jpg') */
  --login-bg-opacity: 0.15;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  position: relative;
}

/* Background image overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--bg-image-opacity);
  pointer-events: none;
  z-index: 0;
}

body > * { position: relative; z-index: 1; }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* Header (sticky — content scrolls beneath) */
header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  height: 32px;
  width: auto;
}

header h1 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

header .subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* Watermark logo (e.g. Marines logo, lower-right corner) */
.watermark-logo {
  position: fixed;
  bottom: 16px;
  right: 16px;
  height: 240px;
  width: auto;
  opacity: 0.2;
  pointer-events: none;
  z-index: 0;
}

/* Login page logo above title */
.login-logo {
  height: 64px;
  width: auto;
  margin-bottom: 12px;
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 {
  font-family: var(--font-heading);
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card h3 {
  font-size: 0.9rem;
  margin: 12px 0 8px;
  color: var(--text-secondary);
}

/* Forms */
.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
  flex-wrap: wrap;
}

input, select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: 0.9rem;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--accent);
}

input::placeholder { color: var(--text-secondary); }

label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
}

/* Buttons */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}

.btn:hover { background: var(--accent-hover); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm {
  padding: 3px 8px;
  font-size: 0.8rem;
}

.btn-success { background: var(--success); }
.btn-success:hover { background: #46c758; }

.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { background: #e0a820; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

/* Fixed-layout user tables (admin panel) for consistent column widths */
table.users-table {
  table-layout: fixed;
}

table.users-table td,
table.users-table th {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tr:hover td { background: var(--bg-tertiary); }

/* Credentials display */
.credential-box {
  background: var(--bg-primary);
  border: 1px solid var(--warning);
  border-radius: var(--radius);
  padding: 12px;
  margin: 8px 0;
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  text-align: center;
}

.credential-box .label {
  font-size: 0.75rem;
  color: var(--warning);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.credential-box .value {
  font-size: 1.4rem;
  font-weight: bold;
  letter-spacing: 0.2em;
}

/* Login screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  position: relative;
}

/* Login background image overlay */
.login-screen::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: var(--login-bg-image);
  background-size: cover;
  background-position: center;
  opacity: var(--login-bg-opacity);
  pointer-events: none;
  z-index: 0;
}

.login-screen > * { position: relative; z-index: 1; }

.login-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 360px;
  text-align: center;
}

.login-box h2 {
  font-family: var(--font-heading);
  margin-bottom: 20px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.login-box input {
  width: 100%;
  margin-bottom: 12px;
  padding: 10px;
}

.login-box .btn {
  width: 100%;
  padding: 10px;
}

/* Status messages */
.msg-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 8px 0;
}

.msg-success {
  color: var(--success);
  font-size: 0.85rem;
  margin: 8px 0;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  padding: 8px 16px;
  cursor: pointer;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  font-size: 0.9rem;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Panels */
.panel { display: none; }
.panel.active { display: block; }

/* Grid */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 768px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
}

/* Session tree */
.session-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.session-header {
  background: var(--bg-tertiary);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.session-header:hover { background: #282e36; }

.session-body { padding: 12px 14px; }

.group-item {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-role { background: var(--badge-role-bg); color: var(--badge-role-fg); }
.badge-session { background: var(--badge-session-bg); color: var(--badge-session-fg); }
.badge-group { background: var(--badge-group-bg); color: var(--badge-group-fg); }

/* Hidden */
.hidden { display: none !important; }

/* Empty state */
.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 24px;
  font-style: italic;
}

/* Report styles */
.report-section {
  margin-bottom: 24px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin: 10px 0;
}

.stat-box {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.stat-box .stat-value {
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--accent);
}

.stat-box .stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* Role editing */
.role-form {
  display: grid;
  grid-template-columns: 80px 1fr 1fr 1fr;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}

.role-form input, .role-form textarea {
  width: 100%;
}

@media (max-width: 768px) {
  .role-form { grid-template-columns: 1fr; }
}

/* ============================================================
 * MODAL OVERLAY
 * ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 540px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 {
  font-family: var(--font-heading);
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ============================================================
 * LEADERBOARD
 * ============================================================ */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th {
  cursor: pointer;
  user-select: none;
}

.leaderboard-table th:hover {
  color: var(--accent);
}

.rank-1 td:first-child { color: var(--gold); font-weight: bold; }
.rank-2 td:first-child { color: var(--silver); font-weight: bold; }
.rank-3 td:first-child { color: var(--bronze); font-weight: bold; }

.leaderboard-filters {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  padding: 4px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}

.filter-btn:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.filter-btn.active { color: var(--accent); border-color: var(--accent); background: var(--badge-role-bg); }

/* ============================================================
 * DRILL FOLDOUT (Report page collapsible sections)
 * ============================================================ */
.drill-foldout {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.drill-foldout-header {
  background: var(--bg-tertiary);
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.drill-foldout-header:hover {
  background: #282e36;
}

/* ============================================================
 * SCORE TOOLTIP
 * ============================================================ */
.score-cell {
  position: relative;
  cursor: help;
}

.score-tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 10;
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.score-cell:hover .score-tooltip {
  display: block;
}

/* ============================================================
 * RANK CHANGE INDICATOR
 * ============================================================ */
.rank-up { color: var(--success); font-size: 0.75rem; margin-left: 4px; }
.rank-down { color: var(--danger); font-size: 0.75rem; margin-left: 4px; }
.rank-same { color: var(--text-secondary); font-size: 0.75rem; margin-left: 4px; }

/* ============================================================
 * TABLET / TOUCH RESPONSIVE
 * ============================================================ */

/* Scrollable table wrapper — prevents wide tables from blowing out layout */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Touch-friendly score tooltip (tap to toggle via JS .tooltip-active class) */
@media (hover: none) and (pointer: coarse) {
  .score-cell:hover .score-tooltip {
    display: none; /* disable hover on touch */
  }
  .score-cell.tooltip-active .score-tooltip {
    display: block;
  }
}

/* Tablet breakpoint (portrait tablets ~768-1024px) */
@media (max-width: 1024px) {
  .container {
    padding: 12px;
  }

  header {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }

  header h1 {
    font-size: 1rem;
  }

  header .subtitle {
    font-size: 0.75rem;
  }

  .card {
    padding: 12px;
  }

  .stat-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
  }

  .stat-box {
    padding: 8px;
  }

  .stat-box .stat-value {
    font-size: 1.1rem;
  }

  .leaderboard-filters {
    gap: 6px;
  }

  .filter-btn {
    padding: 4px 8px;
    font-size: 0.8rem;
  }

  /* Leaderboard: hide less-critical columns on tablet */
  .leaderboard-table td:nth-child(4),
  .leaderboard-table th:nth-child(4) {
    display: none; /* hide ID column */
  }

  .leaderboard-table td,
  .leaderboard-table th {
    padding: 6px 6px;
    font-size: 0.8rem;
  }

  .modal-content {
    width: 95vw;
    padding: 16px;
  }

  /* Admin user table: allow horizontal scroll instead of heavy truncation */
  table.users-table {
    min-width: 600px;
  }
}

/* Phone breakpoint (<= 768px) */
@media (max-width: 768px) {
  header h1 {
    font-size: 0.9rem;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Leaderboard: also hide Role column on phone */
  .leaderboard-table td:nth-child(5),
  .leaderboard-table th:nth-child(5) {
    display: none;
  }

  .leaderboard-table td,
  .leaderboard-table th {
    padding: 5px 4px;
    font-size: 0.75rem;
  }

  .score-tooltip {
    left: auto;
    right: 0;
    transform: none;
  }

  .drill-foldout-header {
    padding: 8px 10px;
  }

  .login-box {
    width: 95vw;
    padding: 20px;
  }
}

/* ============================================================
 * PRINT STYLES
 * ============================================================ */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 11pt;
    font-family: var(--font-body) !important;
  }

  body::before,
  .watermark-logo,
  .login-screen,
  header button,
  .btn,
  .score-tooltip,
  .filter-btn,
  .leaderboard-filters { display: none !important; }

  /* Undo sticky header for print */
  header {
    position: static !important;
    background: none !important;
    border-bottom: 2px solid #000 !important;
    color: #000 !important;
    padding: 8px 0 !important;
  }

  header h1, header .subtitle {
    color: #000 !important;
  }

  header h1 {
    font-family: var(--font-heading) !important;
  }

  .card {
    background: none !important;
    border: 1px solid #ccc !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .card h2 {
    color: #000 !important;
    border-bottom-color: #ccc !important;
  }

  .stat-box {
    background: none !important;
    border: 1px solid #ccc !important;
  }

  .stat-box .stat-value {
    color: #000 !important;
  }

  .badge {
    border: 1px solid #999 !important;
    background: none !important;
    color: #000 !important;
  }

  table { font-size: 10pt; }
  th { color: #333 !important; }
  tr:hover td { background: none !important; }

  .container { max-width: 100%; padding: 0; }

  /* Undo tablet responsive column hiding for print */
  .leaderboard-table td,
  .leaderboard-table th {
    display: table-cell !important;
    padding: 4px 6px !important;
    font-size: 9pt !important;
  }

  /* Expand all collapsible foldouts for print */
  .drill-foldout > div[id] {
    display: block !important;
    height: auto !important;
  }

  .drill-foldout-header span[id$="-arrow"] {
    display: none !important;
  }

  .drill-foldout-header {
    background: #f0f0f0 !important;
    color: #000 !important;
  }

  .drill-foldout-header strong {
    color: #000 !important;
  }

  /* Ensure scroll wrappers don't clip content in print */
  .table-scroll {
    overflow: visible !important;
  }

  /* Override dark inline backgrounds (team probability, foldout headers, etc.) */
  [style*="background:var(--bg-tertiary)"],
  [style*="background: var(--bg-tertiary)"] {
    background: #f5f5f5 !important;
  }

  /* Ensure all stat values and labels are readable on white */
  .stat-label {
    color: #555 !important;
  }

  /* Team probability table rows */
  #team-probability tr {
    background: none !important;
  }
  #team-probability td,
  #team-probability th {
    color: #000 !important;
  }

  /* Team probability breakdown section */
  #team-probability div {
    color: #000 !important;
  }
  #team-probability span {
    color: #333 !important;
  }
  #team-probability strong {
    color: #000 !important;
  }

  /* Team Performance member cards */
  .group-item {
    background: #fff !important;
    border: 1px solid #ccc !important;
    color: #000 !important;
  }

  .group-item strong,
  .group-item span {
    color: #000 !important;
  }

  .empty-state {
    color: #555 !important;
  }

  a { color: #000 !important; text-decoration: none !important; }
}
