/* NGD Backups - Main Stylesheet
   Shares the NGD Phones design system: navy primary, orange accent,
   system font stack, card-based layout. */

:root {
  --color-primary: #1a365d;
  --color-primary-light: #2c5282;
  --color-accent: #ed8936;
  --color-text: #2d3748;
  --color-text-muted: #718096;
  --color-bg: #f7fafc;
  --color-white: #ffffff;
  --color-border: #e2e8f0;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);

  /* Chart tokens. Single-series charts throughout, so one data hue plus an
     emphasis hue. Both validated >= 3:1 against the white card surface;
     the brand accent #ed8936 is 2.48:1 so it stays on buttons only. */
  --chart-series: #2c5282;
  --chart-emphasis: #c05621;
  --chart-grid: #e2e8f0;
  --chart-surface: #ffffff;
  --chart-muted: #a0aec0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
}

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

a {
  color: var(--color-primary-light);
}

/* ---------- Header ---------- */
.site-header {
  background: var(--color-primary);
  color: var(--color-white);
  padding: 1rem 0;
  box-shadow: var(--shadow);
}

.site-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-white);
  text-decoration: none;
}

.logo-tag {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: rgba(255,255,255,0.15);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}

.main-nav {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}

.main-nav a {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  font-weight: 500;
}

.main-nav a:hover,
.main-nav a.active {
  color: var(--color-white);
}

.btn-nav {
  background: var(--color-accent);
  color: var(--color-white) !important;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  transition: background 0.2s;
}

.btn-nav:hover {
  background: #dd6b20;
}

/* Mobile nav toggle — hidden on desktop */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  height: 2px;
  width: 20px;
  margin: 0 auto;
  background: var(--color-white);
  border-radius: 2px;
}

/* ---------- Main content ---------- */
.main-content {
  min-height: calc(100vh - 180px);
  padding: 2rem 0;
}

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  padding: 4rem 0;
}

.hero h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  color: var(--color-primary);
}

.hero p {
  font-size: 1.2rem;
  color: var(--color-text-muted);
  max-width: 640px;
  margin: 0 auto 2rem;
}

.hero .btn {
  margin: 0 0.25rem;
}

/* ---------- Cards ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.card-grid > .card {
  min-width: 0;
}

.card {
  background: var(--color-white);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border);
  transition: box-shadow 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card h3 {
  margin-top: 0;
  color: var(--color-primary);
}

.card-flat:hover {
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  color: var(--color-primary);
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.card-header-row h3,
.card-header-row .card-title {
  margin: 0;
}

/* ---------- Section helpers ---------- */
.section {
  padding: 2rem 0;
}

.section-heading {
  text-align: center;
  margin-bottom: 0.5rem;
  color: var(--color-primary);
}

.section-sub {
  text-align: center;
  color: var(--color-text-muted);
  max-width: 640px;
  margin: 0 auto;
}

.feature-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
}

.feature-list li {
  padding-left: 1.6rem;
  position: relative;
  margin-bottom: 0.5rem;
}

.feature-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--color-accent);
}

/* ---------- Forms ---------- */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  max-width: 420px;
  padding: 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-white);
}

.form-group textarea {
  min-height: 140px;
  resize: vertical;
}

.form-group select {
  cursor: pointer;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: 2px solid var(--color-primary-light);
  outline-offset: 1px;
  border-color: var(--color-primary-light);
}

.form-group .hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.form-full input,
.form-full select,
.form-full textarea {
  max-width: 100%;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0 1.25rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

/* Honeypot — visually removed but not display:none, which some bots detect */
.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  background: var(--color-primary);
  color: var(--color-white);
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.btn:hover {
  background: var(--color-primary-light);
}

.btn-accent {
  background: var(--color-accent);
}

.btn-accent:hover {
  background: #dd6b20;
}

.btn-secondary {
  background: var(--color-white);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-bg);
  color: var(--color-primary);
}

.btn-danger {
  background: #c53030;
}

.btn-danger:hover {
  background: #9b2c2c;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.875rem;
}

/* ---------- Footer ---------- */
.site-footer {
  background: var(--color-primary);
  color: rgba(255,255,255,0.9);
  padding: 2rem 0;
  margin-top: auto;
}

.site-footer .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.footer-nav a {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  margin-left: 1.5rem;
}

.footer-nav a:hover {
  color: var(--color-white);
}

/* ---------- Portal & Admin layout ---------- */
.has-dashboard {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.dash-header {
  padding: 0.75rem 0;
}

.dash-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0 1.5rem;
}

.dash-user {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.9);
}

.dash-user a {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  font-weight: 500;
}

.dash-user a:hover {
  color: var(--color-white);
}

.portal-layout,
.admin-layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - 60px);
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--color-primary);
  color: var(--color-white);
  padding: 1.5rem 0;
}

.sidebar-nav a {
  display: block;
  padding: 0.6rem 1.5rem;
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,0.1);
  color: var(--color-white);
  border-left-color: var(--color-accent);
}

.content-area {
  flex: 1;
  min-width: 0;
  padding: 2rem;
  background: var(--color-bg);
}

.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  margin: 0 0 0.5rem;
  color: var(--color-primary);
  font-size: 1.75rem;
}

.page-header p {
  margin: 0;
  color: var(--color-text-muted);
}

.page-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

.page-header-row .page-header {
  margin-bottom: 0;
}

/* ---------- Alerts ---------- */
.alert {
  padding: 1rem 1.25rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
}

.alert-info {
  background: #bee3f8;
  color: #2c5282;
  border: 1px solid #90cdf4;
}

.alert-warning {
  background: #feebc8;
  color: #744210;
  border: 1px solid #fbd38d;
}

.alert-success {
  background: #c6f6d5;
  color: #276749;
  border: 1px solid #9ae6b4;
}

.alert-error {
  background: #fed7d7;
  color: #742a2a;
  border: 1px solid #feb2b2;
}

/* ---------- Stat tiles (KPI row) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-tile {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
  min-width: 0;
}

.stat-label {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--color-primary);
  /* Proportional figures — tabular-nums reads loose at display sizes */
}

.stat-delta {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.stat-delta .up { color: #276749; font-weight: 600; }
.stat-delta .down { color: #9b2c2c; font-weight: 600; }
.stat-delta .flat { color: var(--color-text-muted); font-weight: 600; }

.stat-sub {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Hero figure — exactly one per view */
.hero-figure {
  font-size: 3rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--color-primary);
  margin: 0;
}

/* ---------- Charts ---------- */
.chart-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
}

.chart-wrap svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 1rem;
}

.chart-grid-line {
  stroke: var(--chart-grid);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart-axis-text {
  fill: var(--color-text-muted);
  font-size: 11px;
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
}

.chart-label-text {
  fill: var(--color-text);
  font-size: 11px;
  font-family: var(--font-sans);
  font-weight: 600;
}

.chart-bar {
  fill: var(--chart-series);
}

.chart-bar-emphasis {
  fill: var(--chart-emphasis);
}

.chart-line {
  fill: none;
  stroke: var(--chart-series);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-area {
  fill: var(--chart-series);
  opacity: 0.1;
}

.chart-dot {
  fill: var(--chart-series);
  stroke: var(--chart-surface);
  stroke-width: 2;
}

.chart-dot-emphasis {
  fill: var(--chart-emphasis);
  stroke: var(--chart-surface);
  stroke-width: 2;
}

.chart-hit {
  fill: transparent;
  cursor: pointer;
}

.chart-crosshair {
  stroke: var(--chart-muted);
  stroke-width: 1;
  pointer-events: none;
}

/* Tooltip */
.chart-tooltip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  background: var(--color-primary);
  color: var(--color-white);
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.12s;
  transform: translate(-50%, -110%);
}

.chart-tooltip.is-visible {
  opacity: 1;
}

.chart-tooltip .tt-label {
  display: block;
  color: rgba(255,255,255,0.75);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chart-tooltip .tt-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Table view toggle beneath a chart — keeps values reachable without color */
.chart-table-toggle {
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.chart-table-toggle summary {
  cursor: pointer;
  color: var(--color-primary-light);
}

.chart-table-toggle table {
  margin-top: 0.75rem;
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  width: 100%;
  min-width: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--color-white);
}

.data-table th,
.data-table td {
  padding: 0.7rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table th {
  background: var(--color-bg);
  color: var(--color-primary);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.data-table th a {
  color: inherit;
  text-decoration: none;
}

.data-table th a:hover {
  text-decoration: underline;
}

.data-table tbody tr:hover {
  background: #fbfdff;
}

.data-table td.num,
.data-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table td.wrap {
  white-space: normal;
  min-width: 220px;
}

.data-table .empty-row td {
  text-align: center;
  color: var(--color-text-muted);
  padding: 2.5rem 1rem;
  white-space: normal;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-active,
.badge-success { background: #c6f6d5; color: #276749; }
.badge-inactive,
.badge-muted   { background: var(--color-border); color: #4a5568; }
.badge-warning { background: #feebc8; color: #744210; }
.badge-error   { background: #fed7d7; color: #742a2a; }
.badge-info    { background: #bee3f8; color: #2c5282; }

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-text-muted);
}

.empty-state h3 {
  color: var(--color-primary);
  margin: 0 0 0.5rem;
}

.empty-state p {
  margin: 0 auto 1.5rem;
  max-width: 480px;
}

/* ---------- Utilities ---------- */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.small { font-size: 0.85rem; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.auth-wrap {
  max-width: 420px;
  margin: 4rem auto;
}

.filter-bar {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.filter-bar .form-group {
  margin-bottom: 0;
}

.filter-bar .form-group input,
.filter-bar .form-group select {
  max-width: 240px;
}

.definition-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.6rem 1.5rem;
  margin: 0;
  font-size: 0.95rem;
}

.definition-list dt {
  color: var(--color-text-muted);
  font-weight: 600;
}

.definition-list dd {
  margin: 0;
  word-break: break-word;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .nav-toggle {
    display: flex;
  }

  .main-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding-top: 0.75rem;
  }

  .main-nav.is-open {
    display: flex;
  }

  .hero h1 {
    font-size: 1.9rem;
  }

  .portal-layout,
  .admin-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    padding: 0.5rem 0;
  }

  .sidebar-nav {
    display: none;
  }

  .sidebar-nav.is-open {
    display: block;
  }

  .content-area {
    padding: 1.25rem;
  }

  .site-footer .container {
    flex-direction: column;
    align-items: flex-start;
  }

  .footer-nav a {
    margin: 0 1rem 0 0;
    display: inline-block;
  }

  .definition-list {
    grid-template-columns: 1fr;
    gap: 0.25rem 0;
  }

  .definition-list dd {
    margin-bottom: 0.75rem;
  }
}

@media print {
  .site-header, .site-footer, .sidebar, .nav-toggle,
  .form-actions, .filter-bar, .btn {
    display: none !important;
  }
  .content-area { padding: 0; }
  body { background: #fff; }
}
