/* Overtone Billing Spine — Design System
   Based on Airflow Portal patterns, branded with Overtone Digital colours.
   overtone-digital.com: Gold #EBC53C, Dark #313131, Helvetica Neue */

/* Responsive utility */
@media (max-width: 768px) { .hide-mobile { display: none !important; } }
@media (min-width: 769px) { .hide-desktop { display: none !important; } }

:root {
  --bg: #f5f5f3;
  --text: #333333;
  --muted: #888888;
  --line: #e8e8e8;
  --card: #ffffff;
  --active: #313131;
  --accent: #EBC53C;
  --accent-hover: #d4b135;
  --accent-text: #313131;
  --danger: #e53e3e;
  --success: #38a169;
  --warning: #dd6b20;
  --info: #3182ce;

  /* Sidebar */
  --sidebar-bg: #313131;
  --sidebar-text: #ffffff;
  --sidebar-muted: rgba(255,255,255,0.5);
  --sidebar-active: #EBC53C;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-width: 240px;
  --sidebar-collapsed: 0px;

  /* Shadows */
  --shadow-1: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-2: 0 4px 12px rgba(0,0,0,0.06);

  /* Typography */
  --font-body: 'Helvetica Neue', Helvetica, Arial, -apple-system, BlinkMacSystemFont, sans-serif;

  /* Shell */
  --shell-max-width: 1400px;
  --shell-pad-x: 24px;
  --top-bar-height: 56px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  font-family: var(--font-body);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 {
  font-family: var(--font-body);
  font-weight: 600;
  margin: 0 0 8px;
}
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.is-hidden { display: none !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ---------- APP LAYOUT ---------- */

#app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- SIDEBAR ---------- */

#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.2s ease;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}
.sidebar-logo .logo-text {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}
.sidebar-logo .logo-sub {
  font-size: 11px;
  color: var(--sidebar-muted);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.sidebar-section {
  padding: 0 12px;
  margin-bottom: 8px;
}
.sidebar-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-muted);
  padding: 8px 12px 4px;
  font-weight: 600;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.75);
  transition: all 0.15s ease;
  cursor: pointer;
  text-decoration: none;
}
.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}
.sidebar-link.active {
  background: rgba(235,197,60,0.15);
  color: var(--sidebar-active);
  font-weight: 600;
}
.sidebar-link .link-icon {
  width: 18px;
  height: 18px;
  opacity: 0.6;
  flex-shrink: 0;
}
.sidebar-link.active .link-icon {
  opacity: 1;
}
.sidebar-link .link-badge {
  margin-left: auto;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 99px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 11px;
  color: var(--sidebar-muted);
}

/* ---------- MAIN CONTENT AREA ---------- */

#main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- TOP BAR ---------- */

#top-bar {
  height: var(--top-bar-height);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--shell-pad-x);
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.top-bar-left h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--text);
}

/* ---------- PAGE CONTENT ---------- */

#page-content {
  flex: 1;
  padding: var(--shell-pad-x);
  max-width: var(--shell-max-width);
  width: 100%;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}
.page-header h1 { margin: 0; }

/* ---------- CARDS ---------- */

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h3 { margin: 0; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* Stat cards (dashboard) */
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-1);
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.stat-card .stat-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* Hero stat card (dark) */
.stat-card.hero {
  background: linear-gradient(135deg, #313131 0%, #3d3d3d 100%);
  color: #fff;
  border: none;
}
.stat-card.hero .stat-label { color: rgba(255,255,255,0.5); }
.stat-card.hero .stat-value { color: var(--accent); }
.stat-card.hero .stat-sub { color: rgba(255,255,255,0.6); }

/* ---------- TABLES ---------- */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.data-table tbody tr {
  transition: background 0.1s ease;
}
.data-table tbody tr:hover {
  background: rgba(235,197,60,0.04);
}
.data-table tbody tr.clickable {
  cursor: pointer;
}

/* ---------- BADGES ---------- */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
  white-space: nowrap;
}
.badge-success { background: #c6f6d5; color: #22543d; }
.badge-warning { background: #fefcbf; color: #744210; }
.badge-danger  { background: #fed7d7; color: #9b2c2c; }
.badge-info    { background: #bee3f8; color: #2a4365; }
.badge-muted   { background: #edf2f7; color: #4a5568; }
.badge-gold    { background: #EBC53C; color: #313131; }

/* ---------- BUTTONS ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-dark {
  background: var(--active);
  color: #fff;
}
.btn-dark:hover { background: #444; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--bg); border-color: #ccc; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #c53030; }

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

/* ---------- FORMS ---------- */

.form-field {
  margin-bottom: 16px;
}
.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(235,197,60,0.15);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 16px;
}

/* ---------- MODAL ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.modal {
  background: var(--card);
  border-radius: 20px;
  padding: 28px;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h2 { margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 8px;
}
.modal-close:hover { background: var(--bg); }

/* ---------- FILTERS ---------- */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-bar select,
.filter-bar input {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  background: var(--card);
}
.filter-bar select:focus,
.filter-bar input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------- JSON VIEWER ---------- */

.json-viewer {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px;
  border-radius: 10px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
}

/* ---------- EMPTY STATE ---------- */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.3;
}
.empty-state h3 { color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 14px; max-width: 400px; margin: 0 auto; }

/* ---------- LOADING ---------- */

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: 8px;
  height: 16px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- TOAST ---------- */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  box-shadow: var(--shadow-2);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------- GOLD DIVIDER ---------- */

.gold-divider {
  width: 40px;
  height: 3px;
  background: var(--accent);
  border: none;
  margin: 12px 0;
}

/* ---------- TABS ---------- */

.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--line);
  margin-bottom: 20px;
}
.tab-bar .tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s ease;
}
.tab-bar .tab:hover { color: var(--text); }
.tab-bar .tab.active {
  color: var(--accent-text);
  border-bottom-color: var(--accent);
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
    --shell-pad-x: 16px;
  }

  #sidebar {
    transform: translateX(-100%);
  }
  #sidebar.mobile-open {
    transform: translateX(0);
    width: 280px;
  }

  .mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
    display: none;
  }
  .mobile-overlay.visible { display: block; }

  #mobile-menu-toggle { display: block; }

  #main-content {
    margin-left: 0;
  }

  .card-grid {
    grid-template-columns: 1fr 1fr;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .data-table {
    display: block;
    overflow-x: auto;
  }
}

@media (max-width: 480px) {
  .card-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- LOGIN PAGE ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
}
.login-card {
  background: var(--card);
  border-radius: 20px;
  padding: 40px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}
.login-card .login-logo {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
}
.login-card h1 {
  font-size: 22px;
  margin-bottom: 4px;
}
.login-card .login-sub {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 28px;
}
.login-card .form-field {
  text-align: left;
}
.login-card .btn {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 14px;
}
.login-message {
  margin-top: 16px;
  padding: 12px;
  border-radius: 10px;
  font-size: 13px;
}
.login-message.success { background: #c6f6d5; color: #22543d; }
.login-message.error   { background: #fed7d7; color: #9b2c2c; }

/* ---------- AVATAR ---------- */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
