@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --accent-from:  #8b5cf6;
  --accent-to:    #06b6d4;
  --accent:       #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-dim:   #ede9fe;
  --bg:           #f8f9fc;
  --surface:      #ffffff;
  --surface-2:    #f3f4f8;
  --border:       rgba(0,0,0,0.08);
  --text:         #1e1e2e;
  --muted:        #6b7280;
  --error:        #f43f5e;
  --success:      #10b981;
  --tag-bg:       #ede9fe;
  --tag-text:     #7c3aed;
  --font-mono:    'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  --font-sans:    'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:    0 4px 24px rgba(0,0,0,0.07), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.06);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── App shell (sidebar + content) ── */
#app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar-wrap {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar {
  width: 220px;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.sidebar-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 12px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -0.01em;
  text-align: center;
  word-break: normal;
  overflow-wrap: break-word;
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-nav {
  list-style: none;
  padding: 10px 10px 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav-item {
  all: unset;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  letter-spacing: 0.01em;
}

.sidebar-nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-company {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-logout {
  all: unset;
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  padding: 5px 0;
  transition: color 0.12s;
}

.sidebar-logout:hover {
  color: var(--error);
}

/* ── Mobile top bar (hidden on desktop) ── */
#mobile-bar {
  display: none;
}

/* ── Drawer backdrop ── */
.drawer-backdrop {
  display: none;
}

/* ── Main layout ── */
main#dashboard {
  flex: 1;
  min-width: 0;
  max-width: 860px;
  margin: 0 auto;
  padding: 36px 32px 72px;
  display: flex;
  flex-direction: column;
  gap: 52px;
}

/* ── Section ── */
section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

section h2 {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── Buttons ── */
button {
  align-self: flex-start;
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 22px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
  letter-spacing: 0.01em;
}

button:hover        { filter: brightness(1.1); }
button:disabled     { opacity: 0.4; cursor: not-allowed; filter: none; }
button:disabled:hover { filter: none; }

/* ── Form card ── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  display: block;
  margin-bottom: 5px;
}

textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea:focus {
  border-color: var(--accent-from);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.12);
}

.lang-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 40px 10px 14px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.4;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.lang-select:focus {
  border-color: var(--accent-from);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.12);
}

.lang-select option {
  font-family: var(--font-sans);
  font-size: 0.875rem;
}

.bulk-upload {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
}

.bulk-upload input[type="file"] {
  min-width: 0;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
}

.bulk-upload-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.bulk-upload input[type="file"]::file-selector-button {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(139,92,246,0.2);
  border-radius: 6px;
  padding: 7px 12px;
  margin-right: 10px;
  font-family: var(--font-sans);
  font-weight: 600;
  cursor: pointer;
}

.bulk-template-button {
  flex-shrink: 0;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 7px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.bulk-template-button:hover {
  background: var(--accent-dim);
  filter: none;
}

.bulk-upload-hint {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 7px;
}

.bulk-preview,
.bulk-progress {
  margin-top: 14px;
  font-size: 0.875rem;
}

.bulk-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.bulk-actions .bulk-cancel {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.bulk-progress-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 7px;
}

.bulk-progress-bar {
  height: 100%;
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  transition: width 0.2s ease;
}

.bulk-progress-count {
  color: var(--muted);
  font-size: 0.8rem;
}

.bulk-success-count {
  color: var(--success);
}

.bulk-failure-count {
  color: var(--error);
}

@media (max-width: 600px) {
  .bulk-upload-controls {
    align-items: stretch;
    flex-direction: column;
  }
}

/* ── Result / error areas ── */
.result-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.error-msg {
  color: var(--error);
  font-size: 0.875rem;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.card-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.card-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 3px;
}

.card p {
  font-size: 0.875rem;
  color: var(--text);
}

.fix-steps {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fix-steps li {
  font-size: 0.875rem;
  color: var(--text);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 5px;
  padding: 2px 9px;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 500;
}

.score-badge {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
}

/* ── Library list ── */
.library-search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.library-search:focus {
  border-color: var(--accent-from);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.12);
}

.library-search::placeholder {
  color: var(--muted);
}

.library-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.library-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.library-item-title {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text);
}

.library-item-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.times-matched {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.empty-msg {
  color: var(--muted);
  font-size: 0.875rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-card {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

/* ── Analytics ── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

@media (max-width: 760px) {
  .stat-cards { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 500px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.stat-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.chart-card--wide {
  grid-column: 1 / -1;
}

@media (max-width: 600px) {
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card--wide { grid-column: unset; }
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.chart-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.chart-wrap canvas {
  max-height: 260px;
}

/* ── Top-unresolved table ── */
.unresolved-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.unresolved-table th,
.unresolved-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.unresolved-table th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.unresolved-table tr:last-child td {
  border-bottom: none;
}

/* ── Voice input ── */
.textarea-wrap {
  position: relative;
}

.mic-btn {
  all: unset;
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
  z-index: 1;
}

.mic-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent-from);
}

.mic-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.mic-btn.listening {
  background: #fff1f2;
  border-color: var(--error);
  animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0   rgba(244, 63, 94, 0.4); }
  50%       { box-shadow: 0 0 0 7px rgba(244, 63, 94, 0);   }
}

.mic-error {
  display: block;
  font-size: 0.75rem;
  color: var(--error);
  min-height: 1rem;
  margin-top: 3px;
}

/* ── Auth gate — split screen ── */
#auth-gate {
  display: flex;
  min-height: 100vh;
}

/* LEFT: 3D scene panel */
.auth-scene-panel {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, #f0ebff 0%, #e0f7fd 100%);
  display: flex;
  align-items: flex-end;
  padding: 40px;
}

.auth-scene-overlay {
  position: relative;
  z-index: 1;
  pointer-events: none;
}

.auth-scene-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.auth-scene-sub {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 6px;
}

/* RIGHT: form panel */
.auth-form-panel {
  width: 440px;
  flex-shrink: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  border-left: 1px solid var(--border);
}

/* Stacked on mobile */
@media (max-width: 768px) {
  #auth-gate { flex-direction: column; }
  .auth-scene-panel {
    height: 260px;
    flex: none;
  }
  .auth-form-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 32px 20px;
  }
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: var(--shadow-md);
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.auth-tab {
  all: unset;
  flex: 1;
  text-align: center;
  padding: 8px 0;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.auth-tab.active {
  color: var(--accent-from);
  border-bottom-color: var(--accent-from);
}

.auth-tab:hover:not(.active) {
  color: var(--text);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.auth-field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-field input:focus {
  border-color: var(--accent-from);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.12);
}

.auth-error {
  font-size: 0.8rem;
  color: var(--error);
  min-height: 1.1rem;
}

/* ── Mobile responsive ── */
@media (max-width: 767px) {
  #app-shell {
    flex-direction: column;
  }

  /* Hide persistent sidebar */
  .sidebar-wrap {
    position: fixed;
    top: 0;
    left: 0;
    width: 220px;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    /* override sticky so it fills the viewport */
    height: 100vh;
  }

  .sidebar-wrap.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
  }

  /* Backdrop */
  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.28);
    z-index: 199;
  }

  /* Mobile top bar */
  #mobile-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
  }

  .mobile-brand {
    font-size: 1rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .hamburger {
    all: unset;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.12s;
  }

  .hamburger:hover { background: var(--surface-2); }

  .hamburger span {
    display: block;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    width: 20px;
  }

  main#dashboard {
    padding: 24px 16px 60px;
  }
}
