:root {
  --primary: #1a6dff;
  --primary-hover: #0b5cd5;
  --primary-soft: #eef4ff;
  --success: #0d9f6e;
  --success-soft: #e6f9f1;
  --warning: #ca8a04;
  --warning-soft: #fef9e7;
  --error: #dc2626;
  --error-soft: #fef2f2;
  --grey: #64748b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.05);
  --shadow: 0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 16px rgba(15,23,42,0.08);
  --shadow-lg: 0 12px 40px rgba(15,23,42,0.12);
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Consolas', monospace;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ========== Auth Screen ========== */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(26,109,255,0.08), transparent),
    radial-gradient(ellipse 60% 50% at 80% 100%, rgba(13,159,110,0.06), transparent),
    var(--bg);
}

.auth-card {
  position: relative;
  background: var(--card);
  border-radius: 16px;
  padding: 48px 40px 40px;
  box-shadow: var(--shadow-lg);
  width: 420px;
  max-width: 92vw;
  text-align: center;
  border: 1px solid var(--border);
  animation: authIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes authIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo {
  color: var(--primary);
  margin-bottom: 20px;
}

.auth-card h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.auth-card p {
  color: var(--text-secondary);
  margin-bottom: 28px;
  font-size: 15px;
}

.auth-card .input-group {
  display: flex;
  gap: 8px;
}

.input-icon-wrap {
  position: relative;
  flex: 1;
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.input-icon-wrap input {
  padding-left: 36px !important;
}

/* ========== App Layout ========== */
#app { display: none; }

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

header .header-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 60px;
  gap: 32px;
}

/* ========== Logo ========== */
header .logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  text-decoration: none;
  letter-spacing: -0.3px;
  transition: color var(--transition);
}

header .logo:hover {
  color: var(--primary);
}

.logo-icon {
  color: var(--primary);
  flex-shrink: 0;
}

/* ========== Navigation ========== */
nav {
  display: flex;
  gap: 2px;
  flex: 1;
}

nav a {
  text-decoration: none;
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

nav a svg {
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity var(--transition);
}

nav a:hover {
  background: var(--bg);
  color: var(--text);
}

nav a:hover svg { opacity: 0.8; }

nav a.active {
  background: var(--primary);
  color: #fff;
}

nav a.active svg { opacity: 1; }

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

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
}

.btn-logout:hover {
  background: var(--error-soft);
  border-color: var(--error);
  color: var(--error);
}

/* ========== Main Content ========== */
main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px;
}

section { display: none; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.section-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

/* ========== Stats Bar ========== */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border);
  transition: background var(--transition);
}

.stat-card:first-child::before { background: var(--primary); }
.stat-card:nth-child(2)::before { background: var(--success); }
.stat-card:nth-child(3)::before { background: var(--warning); }
.stat-card:nth-child(4)::before { background: var(--error); }

.stat-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--border-hover);
}

.stat-card .stat-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -1px;
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  font-weight: 500;
}

/* ========== Filters ========== */
.filters {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-secondary);
  font-weight: 500;
  transition: all var(--transition);
}

.filter-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ========== Tables ========== */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background var(--transition);
}

tbody tr:hover { background: #f8fafc; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--primary-soft); }

/* ========== Badges ========== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.1px;
}

.badge-new { background: #f1f5f9; color: #475569; }
.badge-processed { background: var(--primary-soft); color: #1e40af; }
.badge-sent { background: var(--success-soft); color: #065f46; }
.badge-error { background: var(--error-soft); color: #991b1b; }
.badge-processing { background: var(--warning-soft); color: #92400e; }
.badge-confidence-high { background: var(--success-soft); color: #065f46; }
.badge-confidence-medium { background: var(--warning-soft); color: #92400e; }
.badge-confidence-low { background: var(--error-soft); color: #991b1b; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(26,109,255,0.3);
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(26,109,255,0.35);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #0b8a5e; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-outline {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover {
  background: var(--bg);
  border-color: var(--border-hover);
}

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

/* ========== Forms ========== */
input[type="text"], input[type="password"], input[type="url"], select, textarea {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: all var(--transition);
  background: var(--card);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,109,255,0.1);
}

input::placeholder { color: var(--text-tertiary); }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group { margin-bottom: 18px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

/* ========== Cards ========== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

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

.card-header h2 { font-size: 18px; }

/* ========== Invoice Detail ========== */
.invoice-header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.invoice-field .field-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.invoice-field .field-value {
  font-size: 16px;
  font-weight: 600;
  margin-top: 5px;
  color: var(--text);
}

.invoice-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

/* ========== OCR Text ========== */
details { margin-top: 20px; }

details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 10px 0;
  font-size: 14px;
  display: flex;
  align-items: center;
  transition: color var(--transition);
}

details summary:hover { color: var(--text); }

details[open] summary { margin-bottom: 12px; }

.ocr-text {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
  line-height: 1.7;
  color: var(--text-secondary);
}

/* ========== Upload / Drop Zone ========== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 56px 32px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: #fafbfd;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.drop-zone:hover .drop-icon,
.drop-zone.dragover .drop-icon {
  color: var(--primary);
  transform: translateY(-4px);
}

.drop-zone .drop-icon {
  color: var(--text-tertiary);
  margin-bottom: 16px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.drop-zone .drop-text {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.drop-zone .drop-hint {
  font-size: 13px;
  color: var(--text-tertiary);
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 16px;
  display: none;
}

.progress-bar .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  border-radius: 3px;
  transition: width 0.3s;
  width: 0%;
}

.upload-result {
  margin-top: 20px;
  display: none;
}

/* ========== Toggle Switch ========== */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 12px;
  transition: var(--transition);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ========== Notifications / Toasts ========== */
#notifications {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow-md);
  font-size: 14px;
  max-width: 380px;
  animation: toastIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--error); }
.toast-info { border-left: 4px solid var(--primary); }

@keyframes toastIn {
  from { transform: translateX(100%) scale(0.95); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}

/* ========== Inline Edit ========== */
.inline-form td { padding: 6px 8px; }
.inline-form input { padding: 6px 10px; font-size: 13px; }

/* ========== Pagination ========== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
}

.pagination .btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: var(--radius);
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-secondary);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.25;
}

/* ========== Back Link ========== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 16px;
  font-weight: 500;
  transition: color var(--transition);
}

.back-link:hover { color: var(--primary); }

/* ========== Search ========== */
.search-bar {
  margin-bottom: 16px;
}

.search-bar .input-icon-wrap {
  max-width: 400px;
}

/* ========== Radio Group ========== */
.radio-group { display: flex; flex-direction: column; gap: 10px; }

.radio-label {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
}

.radio-label:hover { border-color: var(--border-hover); }

.radio-label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary);
}

.radio-label input[type="radio"] { margin-top: 4px; accent-color: var(--primary); }
.radio-desc { font-size: 13px; color: var(--grey); margin-top: 4px; line-height: 1.5; }
.field-hint { font-size: 12px; color: var(--grey); margin-top: 6px; }

/* ========== Responsive ========== */
@media (max-width: 768px) {
  header .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 0;
    gap: 8px;
  }

  nav {
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    width: 100%;
    order: 3;
  }

  nav::-webkit-scrollbar { display: none; }

  nav a svg { display: none; }

  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; }
  .invoice-header { grid-template-columns: 1fr 1fr; }
  .section-header { flex-direction: column; gap: 12px; }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ========== Selection ========== */
::selection {
  background: rgba(26,109,255,0.15);
  color: var(--text);
}
