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

:root {
  --background: #ffffff;
  --foreground: #09090b;
  --card: #ffffff;
  --card-foreground: #09090b;
  --muted: #f4f4f5;
  --muted-foreground: #71717a;
  --border: #e4e4e7;
  --input: #e4e4e7;
  --ring: #18181b;
  --radius: 0.5rem;
  --destructive: #ef4444;
  --destructive-foreground: #fafafa;
  --warning: #f59e0b;
  --success: #22c55e;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--background);
  color: var(--foreground);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

h1 {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--muted-foreground);
  font-size: 0.875rem;
  margin-bottom: 2rem;
}

.subtitle a {
  color: var(--foreground);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.subtitle a:hover {
  color: var(--muted-foreground);
}

/* Cards */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* Upload */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--foreground);
  background: var(--muted);
}

.upload-zone p {
  color: var(--muted-foreground);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.upload-zone .label {
  font-weight: 500;
  color: var(--foreground);
  font-size: 1rem;
}

input[type="file"] { display: none; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  height: 2.5rem;
  padding: 0 1rem;
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:hover {
  background: var(--muted);
}

.btn-primary {
  background: var(--foreground);
  color: var(--background);
  border-color: var(--foreground);
}

.btn-primary:hover {
  background: #27272a;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--foreground);
}

.btn-destructive {
  background: var(--destructive);
  color: var(--destructive-foreground);
  border-color: var(--destructive);
}

.btn-destructive:hover {
  background: #dc2626;
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.5;
}

.badge-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.badge-warning {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fed7aa;
}

.badge-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.badge-info {
  background: #f0f9ff;
  color: #075985;
  border: 1px solid #bae6fd;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

/* Issues */
.issue-list {
  list-style: none;
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.issue-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.issue-item:last-child { border-bottom: none; }
.issue-item .badge { flex-shrink: 0; }

.issue-context {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  margin-top: 0.125rem;
}

/* Misc */
.separator {
  height: 1px;
  background: var(--border);
  margin: 1.5rem 0;
}

.hidden { display: none !important; }

/* File info */
.file-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--muted);
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.file-info .name { font-weight: 500; }
.file-info .size { color: var(--muted-foreground); }

.file-info .remove {
  margin-left: auto;
  cursor: pointer;
  color: var(--muted-foreground);
  background: none;
  border: none;
  font-size: 1.125rem;
  line-height: 1;
}

.file-info .remove:hover { color: var(--destructive); }

/* Summary header */
.summary-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.summary-header .badge { font-size: 0.875rem; padding: 0.25rem 0.75rem; }

/* Tabs */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.tab {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-foreground);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--foreground); }

.tab.active {
  color: var(--foreground);
  border-bottom-color: var(--foreground);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 500px;
  overflow-y: auto;
}

.table-wrapper th {
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
}

.mono {
  font-family: "SF Mono", "Cascadia Code", "Consolas", monospace;
  font-size: 0.75rem;
}

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

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
}

.form-group input, .form-group select {
  width: 100%;
  height: 2.5rem;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  padding: 0 0.75rem;
  font-size: 0.875rem;
  background: var(--background);
  color: var(--foreground);
}

.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 2px rgba(24, 24, 27, 0.1);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  margin-top: 0.25rem;
}

/* Footer */
footer {
  text-align: center;
  padding: 2rem 0;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

footer a {
  color: var(--muted-foreground);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

footer a:hover {
  color: var(--foreground);
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 560px;
  width: calc(100% - 2rem);
  max-height: 80vh;
  overflow-y: auto;
  padding: 1.5rem;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--muted-foreground);
  line-height: 1;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
}

.modal-close:hover {
  background: var(--muted);
  color: var(--foreground);
}

.modal h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.modal .dev-info {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.modal .dev-info a {
  color: var(--foreground);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.modal .changelog-title {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.modal .changelog-entry {
  margin-bottom: 1rem;
}

.modal .changelog-entry h4 {
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.modal .changelog-entry .date {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  margin-bottom: 0.375rem;
}

.modal .changelog-entry ul {
  list-style: disc;
  padding-left: 1.25rem;
  font-size: 0.8125rem;
  color: var(--foreground);
}

.modal .changelog-entry ul li {
  margin-bottom: 0.125rem;
}

/* Slip Edit Modal (wider) */
#slip-edit-modal .modal {
  max-width: 700px;
}

/* Field-level issue highlighting */
.form-group.has-error input,
.form-group.has-error select {
  border-color: var(--destructive);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15);
}

.form-group.has-warning input,
.form-group.has-warning select {
  border-color: var(--warning);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.15);
}

.field-issue {
  font-size: 0.7rem;
  margin-top: 0.25rem;
  line-height: 1.3;
}

.field-issue.error { color: #991b1b; }
.field-issue.warning { color: #92400e; }

/* Clickable slip rows */
#slips-tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

#slips-tbody tr:hover {
  background: var(--muted);
}

/* Clickable issue items */
.issue-item.clickable {
  cursor: pointer;
  transition: background 0.1s;
}

.issue-item.clickable:hover {
  background: var(--muted);
}

/* Edited badge */
.badge-edited {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* Amount rows in edit modal */
.edit-amount-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.edit-amount-row .form-group {
  margin-bottom: 0;
}

.edit-amount-row input {
  font-family: "SF Mono", "Cascadia Code", "Consolas", monospace;
}

/* SIN field with toggle */
.sin-field-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.sin-field-wrapper input {
  width: 100%;
  padding-right: 2.5rem;
}

.sin-toggle {
  position: absolute;
  right: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted-foreground);
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
}

.sin-toggle:hover {
  color: var(--foreground);
  background: var(--muted);
}

/* Tooltip trigger (? icon) */
.tooltip-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  font-size: 0.625rem;
  font-weight: 700;
  border-radius: 50%;
  background: var(--muted);
  color: var(--muted-foreground);
  cursor: pointer;
  vertical-align: middle;
  margin-left: 0.25rem;
  position: relative;
}

.tooltip-trigger:hover {
  background: var(--border);
  color: var(--foreground);
}

/* Tooltip bubble */
.tooltip-bubble {
  display: none;
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--foreground);
  color: var(--background);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.5;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  width: 280px;
  text-align: left;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 50;
  white-space: normal;
}

.tooltip-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--foreground);
}

.tooltip-bubble strong {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.75rem;
}

.tooltip-bubble ol {
  list-style: decimal;
  padding-left: 1.125rem;
  margin: 0;
}

.tooltip-bubble ol li {
  margin-bottom: 0.125rem;
}

.tooltip-trigger.active .tooltip-bubble {
  display: block;
}

/* ============================================================
   Auth UI — Phase 3
   ============================================================ */

/* Button size modifier */
.btn-sm {
  height: 2rem;
  font-size: 0.8125rem;
  padding: 0 0.75rem;
}

/* Auth header bar */
#auth-header {
  width: 100%;
  background: var(--muted);
  border-bottom: 1px solid var(--border);
}

.auth-header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.375rem 1rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
}

#auth-user-info {
  font-size: 0.8125rem;
  color: var(--muted-foreground);
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .auth-header-inner {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}
