/* ============================================================
   OpenWay Analyzer — Dark Theme
   Brand: Azure Radiance #009DFF · Tuna #343440 · Raleway
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  /* Backgrounds */
  --bg-body:     #13131b;
  --bg-sidebar:  #1a1a26;
  --bg-surface:  #1f1f2e;
  --bg-elevated: #272738;
  --bg-input:    #181826;

  /* Borders */
  --border:       #2c2c42;
  --border-hover: #3c3c56;

  /* Brand */
  --accent:      #009DFF;
  --accent-dark: #0080d9;
  --accent-dim:  rgba(0, 157, 255, 0.14);
  --accent-glow: 0 0 0 3px rgba(0, 157, 255, 0.22);

  /* Text */
  --text-primary:   #e2e2ee;
  --text-secondary: #8a8aa6;
  --text-muted:     #52527a;

  /* Status */
  --s-queued-bg:    rgba(100, 116, 255, 0.14);
  --s-queued-text:  #9aa8ff;
  --s-running-bg:   rgba(245, 158, 11, 0.14);
  --s-running-text: #fbbf24;
  --s-done-bg:      rgba(16, 185, 129, 0.14);
  --s-done-text:    #34d399;
  --s-fail-bg:      rgba(239, 68, 68, 0.14);
  --s-fail-text:    #f87171;

  /* Misc */
  --radius:     6px;
  --radius-lg:  10px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.35);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.45);
  --transition: 0.15s ease;
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Raleway", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: #4db8ff; }

h1, h2, h3, h4 { font-weight: 700; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 224px;
  background: var(--bg-sidebar);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  z-index: 100;
}

.sidebar-brand {
  padding: 1.4rem 1.5rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}


.sidebar-nav { display: flex; flex-direction: column; flex: 1; padding: 0.5rem 0; }

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 0.6rem 1.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  border-left: 3px solid transparent;
  gap: 0.6rem;
}

.sidebar-link:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-link.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ---------- Main content ---------- */
.main-content {
  margin-left: 224px;
  padding: 1.75rem 2rem 2.5rem;
  min-height: 100vh;
}

.container { max-width: 1100px; margin: 2rem auto; padding: 0 1.5rem; }

/* ---------- Page header ---------- */
.main-content > h1 { margin-bottom: 1.75rem; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
}
.page-header h1 { margin: 0; }

/* ---------- Flash messages ---------- */
.flash-messages { margin-bottom: 1.5rem; }
.flash {
  padding: 0.75rem 1rem 0.75rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}
.flash-success { background: var(--s-done-bg);    color: var(--s-done-text);    border-color: var(--s-done-text); }
.flash-error   { background: var(--s-fail-bg);    color: var(--s-fail-text);    border-color: var(--s-fail-text); }
.flash-warning { background: var(--s-running-bg); color: var(--s-running-text); border-color: var(--s-running-text); }

/* ---------- Auth layout ---------- */
.container:has(.auth-card) {
  min-height: 100vh;
  margin: 0;
  max-width: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at 25% -5%, #0e1b38 0%, var(--bg-body) 65%);
}

/* Auth nav bar */
.auth-nav {
  display: flex;
  align-items: center;
  padding: 1rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: rgba(19, 19, 27, 0.85);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 0.625rem;
}

.auth-nav-logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  color: #fff;
  font-family: 'Sora', sans-serif;
  flex-shrink: 0;
}

.auth-nav-title {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.auth-nav-title span {
  color: var(--text-secondary);
  font-weight: 400;
}

/* Auth card */
.auth-card {
  max-width: 420px;
  width: 100%;
  margin: auto;
  padding: 2.5rem;
  border-radius: 14px;
  background: #0d1420;
  border: 1px solid #1c2740;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.auth-card h1 {
  font-family: 'Sora', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: #e8ecf4;
}

.auth-subtitle {
  font-size: 0.8rem;
  color: #7b8ba5;
  margin-bottom: 1.75rem;
  display: block;
}

/* Auth-specific form controls */
.auth-card .form-group label {
  color: #7b8ba5;
}

.auth-card .form-control {
  background: #141e30;
  border-color: #1c2740;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  color: #e8ecf4;
  border-radius: 8px;
}

.auth-card .form-control:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.auth-card .form-control::placeholder {
  color: #3d4f6b;
}

/* Auth primary button — gradient */
.auth-card .btn-primary {
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border: none;
  box-shadow: 0 4px 18px rgba(59, 130, 246, 0.3);
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 8px;
  width: 100%;
  padding: 0.65rem 1rem;
  font-size: 0.875rem;
}

.auth-card .btn-primary:hover {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  box-shadow: 0 6px 24px rgba(59, 130, 246, 0.45);
  transform: translateY(-1px);
}

.auth-card .btn {
  border-radius: 8px;
}

/* Auth backup codes */
.auth-card .backup-code {
  background: #0a1020;
  border-color: #1c2740;
  font-family: 'JetBrains Mono', monospace;
  color: #60a5fa;
}

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.875rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.925rem;
  font-family: inherit;
  height: 2.5rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--accent-glow);
}

.form-control::placeholder { color: var(--text-muted); }

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a8aa6' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
  cursor: pointer;
}

select.form-control option { background: var(--bg-elevated); }

.form-check { display: flex; align-items: center; gap: 0.5rem; }
.form-check input[type="checkbox"] {
  width: 1rem; height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.field-error { color: var(--s-fail-text); font-size: 0.82rem; margin-top: 0.2rem; display: block; }

.form-card {
  max-width: 540px;
  background: var(--bg-surface);
  padding: 2rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.form-actions { margin-top: 1.75rem; display: flex; gap: 0.75rem; align-items: center; }
.form-row { display: flex; gap: 1rem; }
.form-group-half { flex: 1; }

/* ---------- Searchable select ---------- */
.searchable-select { position: relative; }
.ss-dropdown {
  display: none;
  position: absolute;
  z-index: 200;
  top: 100%; left: 0; right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hover);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-md);
}
.ss-dropdown.ss-open { display: block; }
.ss-option {
  padding: 0.5rem 0.875rem;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-primary);
  transition: background var(--transition);
}
.ss-option:hover { background: var(--accent-dim); color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--border-hover);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-elevated);
  border-color: var(--text-muted);
  color: var(--text-primary);
  text-decoration: none;
  transform: translateY(-1px);
}

.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 157, 255, 0.3);
}

.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 157, 255, 0.4);
}

.btn-warning { background: rgba(245,158,11,0.15); color: #fbbf24; border-color: rgba(245,158,11,0.35); }
.btn-warning:hover { background: rgba(245,158,11,0.25); color: #fbbf24; }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* ---------- Tables ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.data-table th, .data-table td {
  padding: 0.65rem 0.875rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.data-table th {
  background: var(--bg-elevated);
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-elevated); }
.data-table tbody tr.clickable-row { cursor: pointer; }
.data-table tbody tr.clickable-row:hover { background: var(--accent-dim); }

.row-inactive { opacity: 0.45; }
.row-total { font-weight: 700; background: var(--bg-elevated) !important; border-top: 1px solid var(--border-hover); }
.actions { white-space: nowrap; }
.inline-form { display: inline; }
.details-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ---------- Stats grid ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-surface);
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  text-align: center;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-dim), var(--shadow-sm);
}

.stat-value {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.stat-label { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.3rem; font-weight: 600; }

.stat-card-link { text-decoration: none; cursor: pointer; }
.stat-card-link:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-dim), var(--shadow-sm); text-decoration: none; }
.stat-card-link:hover .stat-value { color: #4db8ff; }

/* Online presence indicator */
.online-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--s-done-text);
  box-shadow: 0 0 6px var(--s-done-text);
  margin-right: 5px;
  vertical-align: middle;
  animation: badge-pulse 2s ease-in-out infinite;
}

.btn-danger { background: rgba(239,68,68,0.12); color: var(--s-fail-text); border-color: rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.22); color: var(--s-fail-text); }

/* ---------- Chart section ---------- */
.chart-section { margin-bottom: 2rem; }
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.chart-header h2 { margin: 0; font-size: 1rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.06em; }
.chart-period-switch { display: flex; gap: 0.25rem; }
.btn-period {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text-secondary);
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
}
.btn-period.active { background: var(--accent-dim); color: var(--accent); border-color: rgba(0,157,255,0.4); }
.btn-period:hover { transform: none; }
.chart-container {
  position: relative;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 1.25rem;
  height: 220px;
}
.btn-nav {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  width: 20px;
  height: 20px;
  padding: 0;
  font-size: 0.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.btn-nav:hover:not(:disabled) { color: var(--text-primary); border-color: var(--accent); }
.btn-nav:disabled { opacity: 0.25; cursor: default; }
.chart-nav-arrow { position: absolute; z-index: 1; }

/* ---------- Pagination ---------- */
.pagination {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
.page-info { font-size: 0.875rem; color: var(--text-secondary); }

/* ---------- QR & backup codes ---------- */
.qr-container { text-align: center; margin: 1.5rem 0; }
.qr-container img { border: 4px solid var(--bg-elevated); border-radius: var(--radius); box-shadow: var(--shadow-md); }

.backup-codes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin: 1.5rem 0;
}
.backup-code {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.5rem;
  text-align: center;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: "Courier New", monospace;
  letter-spacing: 2px;
  color: var(--text-primary);
}
.warning-text { color: var(--s-fail-text); font-weight: 600; }

/* ---------- Status badges ---------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.status-badge::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status-queued    { background: var(--s-queued-bg);  color: var(--s-queued-text); }
.status-running   { background: var(--s-running-bg); color: var(--s-running-text); animation: badge-pulse 2s ease-in-out infinite; }
.status-completed { background: var(--s-done-bg);    color: var(--s-done-text); }
.status-failed    { background: var(--s-fail-bg);    color: var(--s-fail-text); }

@keyframes badge-pulse { 0%,100% { opacity: 0.7; } 50% { opacity: 1; } }

/* ---------- Filter bars ---------- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.filter-bar label { font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.filter-select { width: auto; min-width: 200px; }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  background: var(--bg-surface);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.filter-group { display: flex; flex-direction: column; gap: 0.25rem; }
.filter-group label { font-size: 0.78rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.filter-group select, .filter-group input, .filter-group .searchable-select { width: 100%; }
.filter-grid-compact { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.filter-reset { display: flex; align-items: flex-end; min-width: auto; }
.filter-reset .btn { height: 2.5rem; }

/* ---------- Submit form — input sections ---------- */
.input-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: border-color var(--transition), opacity var(--transition);
}
.input-section.active {
  border-color: var(--accent);
  cursor: default;
}
.input-section.inactive { opacity: 0.4; }
.input-section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}
.input-section.active .input-section-label { color: var(--accent); }
.input-or {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 0.35rem 0;
}
.form-row .form-group { flex: 1; }

/* ---------- RRN submit ---------- */
textarea.form-control { height: auto; }
.rrn-textarea { font-family: "Courier New", Courier, monospace; font-size: 0.875rem; resize: vertical; }
.rrn-counter { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.3rem; }
.file-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.25rem; display: block; }

/* ---------- Status/run page ---------- */
.status-card {
  background: var(--bg-surface);
  padding: 2rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  max-width: 620px;
  box-shadow: var(--shadow-sm);
}
.status-row { display: flex; gap: 0.75rem; margin-bottom: 0.6rem; align-items: center; }
.status-label { font-weight: 700; color: var(--text-secondary); min-width: 90px; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- Progress bar ---------- */
.progress-bar-container {
  background: var(--bg-elevated);
  border-radius: 4px;
  height: 6px;
  margin: 1rem 0;
  overflow: hidden;
}

.progress-bar {
  background: linear-gradient(90deg, var(--accent) 0%, #4db8ff 100%);
  height: 100%;
  width: 0%;
  border-radius: 4px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 8px rgba(0, 157, 255, 0.5);
  animation: progress-glow 2s ease-in-out infinite;
}

@keyframes progress-glow {
  0%,100% { box-shadow: 0 0 6px rgba(0,157,255,0.4); }
  50%      { box-shadow: 0 0 14px rgba(0,157,255,0.7); }
}

/* ---------- Report detail ---------- */
.report-summary { margin-bottom: 2rem; }
.download-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; flex-wrap: wrap; }
.report-frame-container { margin-top: 2rem; }
.report-frame {
  width: 100%;
  min-height: 600px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.ops-summary-card { margin-top: 2rem; }
.ops-summary-card h3 { margin-bottom: 0.75rem; }
.rejected-section { margin-top: 1.5rem; }
.rejected-section h3 { color: var(--s-fail-text); margin-bottom: 0.5rem; }
.rejected-list {
  background: var(--s-fail-bg);
  border: 1px solid rgba(239,68,68,0.2);
  padding: 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  max-height: 200px;
  overflow-y: auto;
  color: var(--s-fail-text);
}

/* ---------- Error page ---------- */
.error-page { text-align: center; padding: 5rem 1rem; }
.error-page h1 { font-size: 5rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.error-page p { font-size: 1.1rem; color: var(--text-secondary); margin-bottom: 2rem; }

/* ---------- Misc ---------- */
.text-muted { color: var(--text-muted); }

/* ---------- Flatpickr Today button ---------- */
.fp-today-btn {
  display: block; width: 100%; padding: 0.4rem;
  background: var(--accent-dim); border: none; border-top: 1px solid var(--border);
  color: var(--accent); font-family: inherit; font-size: 0.82rem; font-weight: 600;
  cursor: pointer; transition: background var(--transition);
}
.fp-today-btn:hover { background: var(--accent); color: #fff; }
