:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-hover: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --orange: #d29922;
  --red: #f85149;
  --purple: #bc8cff;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Auth Gate */
.auth-gate {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.auth-card h1 { font-size: 1.5rem; margin-bottom: 8px; }
.auth-card p { color: var(--text-dim); margin-bottom: 24px; font-size: 0.9rem; }

.auth-error {
  color: var(--red);
  font-size: 0.85rem;
  margin-top: 12px;
  min-height: 1em;
}

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  width: 100%;
}
.btn-primary:hover { opacity: 0.9; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-icon:hover { border-color: var(--red); color: var(--red); }

/* App Layout */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.header h1 { font-size: 1.3rem; }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-card);
  border-radius: 10px;
  padding: 4px;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
}
.tab.active {
  background: var(--bg-hover);
  color: var(--text);
}

/* Summary Cards */
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.card-value {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Chart */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 24px;
}
.chart-container h2 { font-size: 0.9rem; margin-bottom: 12px; color: var(--text-dim); }
#cost-chart { width: 100% !important; height: 180px !important; }

/* Sections */
.section {
  margin-bottom: 24px;
}
.section h2 {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* Model Breakdown */
.model-breakdown { display: flex; flex-direction: column; gap: 8px; }
.model-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.model-name { font-size: 0.85rem; font-weight: 500; }
.model-cost { font-size: 0.85rem; color: var(--accent); font-weight: 600; }
.model-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.model-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* Session List */
.session-list { display: flex; flex-direction: column; gap: 6px; }
.session-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  transition: background 0.2s;
}
.session-item:hover { background: var(--bg-hover); }
.session-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.session-model {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--purple);
}
.session-cost { font-size: 0.8rem; color: var(--green); font-weight: 600; }
.session-title {
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.session-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  gap: 12px;
}

/* Footer */
.footer {
  text-align: center;
  padding: 20px 0;
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
}

/* View Navigation */
.view-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-card);
  border-radius: 10px;
  padding: 4px;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
}
.nav-btn.active {
  background: var(--bg-hover);
  color: var(--text);
}

/* Button variants */
.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: 6px;
}
.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--accent); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

/* Instructions View */
.instructions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.instructions-header h2 {
  font-size: 1.1rem;
}

.compliance-summary {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.compliance-summary .card {
  padding: 12px;
}
.compliance-summary .card-value {
  font-size: 1.3rem;
}

.instructions-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}
.sync-timestamp {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: right;
}

.instructions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.instruction-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
}
.instruction-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.instruction-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-hover);
}
.instruction-category {
  font-size: 0.75rem;
  color: var(--text-dim);
  flex: 1;
}
.instruction-content {
  font-size: 0.85rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 8px;
}
.instruction-status {
  font-size: 0.75rem;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.instruction-status-detail {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.check-line {
  font-size: 0.7rem;
  color: var(--text-dim);
  display: flex;
  gap: 4px;
}

/* Modal Dialog */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h3 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}
.modal-card label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.modal-input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
}
.modal-input:focus {
  outline: none;
  border-color: var(--accent);
}
.modal-textarea {
  min-height: 100px;
  resize: vertical;
}
.modal-btn-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* Compliance Note */
.compliance-note {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.compliance-note strong { color: var(--text); }
.compliance-note em { color: var(--orange); }

/* Current Instructions & Compliance UI */
.header-subtitle, .section-heading p, .compliance-top p, .sync-status { color: var(--text-dim); font-size: 0.78rem; margin-top: 3px; }
.primary-nav { display: flex; gap: 4px; margin-bottom: 20px; padding: 4px; background: var(--bg-card); border-radius: 10px; }
.nav-button { flex: 1; padding: 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text-dim); font-weight: 600; cursor: pointer; }
.nav-button.active { color: var(--text); background: var(--bg-hover); }
.section-heading, .compliance-top, .instruction-card-top, .instruction-actions, .usage-meter-label, .dialog-header, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading { margin-bottom: 16px; align-items: flex-start; }
.section-heading h2, .compliance-panel h3 { font-size: 1.05rem; }
.btn-compact { width: auto; white-space: nowrap; padding: 9px 14px; }
.btn-small { padding: 7px 12px; font-size: 0.78rem; }
.btn-danger { background: transparent; color: var(--red); border: 1px solid rgba(248,81,73,.5); border-radius: 7px; cursor: pointer; }
.inline-message { padding: 11px 13px; margin-bottom: 14px; border: 1px solid var(--border); border-radius: 8px; font-size: .82rem; }
.inline-message.error { color: var(--red); border-color: rgba(248,81,73,.5); }
.inline-message.success { color: var(--green); border-color: rgba(63,185,80,.5); }
.compliance-panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.test-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.test-count { padding: 10px; border-radius: 8px; background: var(--bg); text-align: center; }
.test-count strong, .test-count span { display: block; }
.test-count strong { font-size: 1.25rem; }.test-count span { color: var(--text-dim); font-size: .7rem; }
.test-count.pass strong { color: var(--green); }.test-count.fail strong { color: var(--red); }.test-count.pending strong { color: var(--orange); }
.store-usage { display: grid; gap: 8px; margin-bottom: 14px; }
.usage-meter { background: var(--bg-card); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; }
.usage-meter-label { font-size: .72rem; margin-bottom: 7px; }.usage-meter-label span { color: var(--text-dim); }
.usage-meter-track { height: 5px; overflow: hidden; background: var(--border); border-radius: 5px; }.usage-meter-fill { height: 100%; background: var(--accent); }.usage-meter-fill.over { background: var(--red); }
.instruction-list { display: flex; flex-direction: column; gap: 9px; }
.instruction-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.instruction-title { color: var(--text); font-size: .95rem; line-height: 1.3; margin: 11px 0 6px; overflow-wrap: anywhere; }
.instruction-card .instruction-content { color: var(--text-dim); }
.instruction-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.store-badge, .category-badge, .status-badge { padding: 3px 7px; border-radius: 999px; font-size: .66rem; font-weight: 700; }
.store-badge { background: rgba(88,166,255,.14); color: var(--accent); }.store-badge.memory { background: rgba(188,140,255,.14); color: var(--purple); }
.category-badge { background: var(--bg-hover); color: var(--text-dim); }.status-badge.pass { color: var(--green); }.status-badge.fail { color: var(--red); }.status-badge.pending { color: var(--orange); }
.instruction-status { color: var(--text-dim); font-size: .72rem; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 9px; }
.check-line.pass { color: var(--green); }.check-line.fail { color: var(--red); }
.instruction-actions { justify-content: flex-end; margin-top: 11px; }
.instruction-dialog { width: min(520px, calc(100% - 28px)); border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); color: var(--text); padding: 20px; }
.instruction-dialog::backdrop { background: rgba(0,0,0,.72); }
.instruction-dialog form { display: grid; gap: 8px; }.instruction-dialog label { color: var(--text-dim); font-size: .78rem; margin-top: 5px; }
.instruction-dialog input, .instruction-dialog select, .instruction-dialog textarea { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 7px; color: var(--text); background: var(--bg); font: inherit; }
.dialog-actions { justify-content: flex-end; margin-top: 10px; }
.compliance-note { margin-top: 12px; }

/* Responsive */
@media (min-width: 600px) {
  .cards { grid-template-columns: repeat(4, 1fr); }
}
