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

:root {
  --bg:        #f4f6f9;
  --surface:   #ffffff;
  --border:    #dde1e8;
  --primary:   #2563eb;
  --primary-h: #1d4ed8;
  --danger:    #dc2626;
  --success:   #16a34a;
  --text:      #1e293b;
  --muted:     #64748b;
  --check:     #2563eb;
  --row-alt:   #f8fafc;
  --shadow:    0 1px 4px rgba(0,0,0,.08);
  --radius:    8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Top Navigation ────────────────────────────────────────────────────────── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 200;
  background: #1e293b;
  border-bottom: 1px solid #0f172a;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.18);
}

.topnav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topnav-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topnav-home {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  color: #94a3b8;
  text-decoration: none;
  transition: color 0.15s ease;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.topnav-home:hover { color: #e2e8f0; }

.topnav-sep {
  color: #334155;
  font-weight: 300;
  font-size: 16px;
  user-select: none;
}

.topnav-title {
  font-size: 15px;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.topnav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-dark-toggle {
  background: transparent;
  border: 1px solid #334155;
  color: #94a3b8;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-dark-toggle:hover {
  background: #334155;
  color: #f1f5f9;
  border-color: #475569;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
.page-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

header {
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
}

header h1 {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
}

header p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.credit-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.82rem;
}
.credit-link:hover { text-decoration: underline; }

section { margin-bottom: 24px; }

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

.section-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ── Author Input ──────────────────────────────────────────────────────────── */
.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.input-row input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.input-row input[type="text"]:focus { border-color: var(--primary); }
.input-row input[type="text"].shake {
  animation: shake .3s ease;
  border-color: var(--danger);
}

.btn {
  padding: 9px 18px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background .15s, opacity .15s;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-outline   { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--row-alt); }
.btn-danger    { background: transparent; color: var(--danger); border: 1px solid #fca5a5; }
.btn-danger:hover { background: #fef2f2; }

/* ── Author Chips ──────────────────────────────────────────────────────────── */
.author-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  min-height: 0;
}

.author-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  padding: 5px 10px 5px 12px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #1e40af;
}

.chip-actions { display: flex; gap: 2px; }

.chip-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #3b82f6;
  font-size: 0.85rem;
  padding: 1px 4px;
  border-radius: 4px;
  line-height: 1;
}
.chip-btn:hover { background: #dbeafe; }
.chip-remove { color: var(--danger) !important; }
.chip-remove:hover { background: #fee2e2 !important; }

/* ── Table ─────────────────────────────────────────────────────────────────── */
.table-outer {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface);
}

.credit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.credit-table th, .credit-table td {
  padding: 0;
  border: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}

.credit-table thead th {
  background: #f1f5f9;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 4px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.col-author {
  min-width: 100px;
  width: 100px;
  text-align: left !important;
  padding-left: 12px !important;
  position: sticky;
  left: 0;
  background: inherit;
  z-index: 1;
}

thead .col-author { z-index: 3; }

.col-role { width: 58px; min-width: 58px; }
.col-count { width: 48px; min-width: 48px; font-weight: 600; color: var(--primary); }

.role-label {
  display: block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.72rem;
  padding: 8px 4px;
  white-space: nowrap;
  cursor: help;
  max-height: 160px;
}

.credit-table tbody tr { background: var(--surface); }
.credit-table tbody tr:nth-child(even) { background: var(--row-alt); }
.credit-table tbody tr:hover { background: #eff6ff; }

.author-name {
  font-weight: 500;
  color: var(--text);
  font-size: 0.875rem;
}

.role-check {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--check);
}

.count-badge { font-size: 0.82rem; }

.footer-row td {
  background: #f8fafc;
  font-size: 0.78rem;
  color: var(--primary);
  font-weight: 700;
  padding: 4px 2px;
  border-top: 2px solid var(--border);
}
.footer-label {
  color: var(--muted) !important;
  font-weight: 500 !important;
  font-style: italic;
  padding-left: 12px !important;
}
.col-total { font-size: 0.78rem; }

/* ── Empty State ───────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  color: var(--muted);
  text-align: center;
  gap: 8px;
}

.empty-icon { font-size: 2.5rem; }
.empty-state p { font-size: 0.875rem; }

/* ── Generate Row ──────────────────────────────────────────────────────────── */
.generate-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.style-select-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.style-select-wrap label {
  font-size: 0.875rem;
  color: var(--muted);
  white-space: nowrap;
}

select {
  padding: 9px 32px 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  outline: none;
  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='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select:focus { border-color: var(--primary); }

/* ── Output ────────────────────────────────────────────────────────────────── */
.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}

.style-info { display: flex; align-items: center; gap: 8px; }

.style-badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  letter-spacing: .4px;
}

.style-desc {
  font-size: 0.8rem;
  color: var(--muted);
}

.output-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 60px;
}

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 9999;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Action bar ────────────────────────────────────────────────────────────── */
.action-bar {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

/* ── Dark Mode ─────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --border:    #334155;
  --primary:   #3b82f6;
  --primary-h: #2563eb;
  --danger:    #f87171;
  --success:   #10b981;
  --text:      #f1f5f9;
  --muted:     #94a3b8;
  --check:     #3b82f6;
  --row-alt:   #162032;
  --shadow:    0 1px 4px rgba(0,0,0,.3);
}

[data-theme="dark"] body { background: var(--bg); }

/* Inputs & selects */
[data-theme="dark"] input[type="text"],
[data-theme="dark"] select {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
[data-theme="dark"] input[type="text"]::placeholder { color: #64748b; }
[data-theme="dark"] input[type="text"]:focus { border-color: var(--primary); }

/* Cards & surfaces */
[data-theme="dark"] .card { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] .output-box { background: #162032; color: var(--text); }

/* Table */
[data-theme="dark"] .credit-table thead th { background: #162032; color: var(--muted); }
[data-theme="dark"] .credit-table tbody tr { background: var(--surface); }
[data-theme="dark"] .credit-table tbody tr:nth-child(even) { background: var(--row-alt); }
[data-theme="dark"] .credit-table tbody tr:hover { background: #1e3a5f; }
[data-theme="dark"] .table-outer { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] .footer-row td { background: #162032; }

/* Author chips */
[data-theme="dark"] .author-chip {
  background: #1e3a5f;
  border-color: #2d5a9e;
  color: #93c5fd;
}

/* Section title */
[data-theme="dark"] .section-title { color: var(--muted); }

/* ── Animations ────────────────────────────────────────────────────────────── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-6px); }
  75%       { transform: translateX(6px); }
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  header h1 { font-size: 1.25rem; }
  .generate-row { flex-direction: column; align-items: flex-start; }
  .output-header { flex-direction: column; align-items: flex-start; }
}
