:root {
  --accent: #2b5797;
  --accent-hover: #1f4275;
  --accent-tint: #e8eef7;
  --bg: #f7f6f3;
  --surface: #ffffff;
  --text: #000000;
  --muted: #555b63;
  --border: #dedbd4;

  --success: #1a7f37;
  --success-bg: #e6f4ea;
  --warning: #8a5a00;
  --warning-bg: #fdf3dc;
  --danger: #c5221f;
  --danger-bg: #fce8e6;
  --neutral-bg: #eeece7;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
[hidden] { display: none !important; }

/* ---------- Icons: monochrome images recolored through a CSS mask ---------- */
.icon {
  display: inline-block;
  width: var(--size, 20px);
  height: var(--size, 20px);
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask: var(--src) center / contain no-repeat;
  mask: var(--src) center / contain no-repeat;
}
.illustration { width: var(--size, 96px); height: var(--size, 96px); object-fit: contain; }
.spin { animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons and forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem 1rem; border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer;
  background: var(--accent); color: #fff; transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
}
a.btn:hover { color: #fff; }
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .nav a:focus-visible {
  outline: 3px solid rgba(43, 87, 151, 0.35); outline-offset: 2px;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--accent); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--accent-tint); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--border); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-success { background: var(--success); }
.btn-success:hover:not(:disabled) { background: #146c2e; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.82rem; }
.btn-block { width: 100%; }

label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.3rem; }
.field { margin-bottom: 0.9rem; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.required::after { content: " *"; color: var(--danger); }
input, select, textarea {
  width: 100%; padding: 0.55rem 0.7rem; font: inherit; font-size: 0.92rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
textarea { resize: vertical; min-height: 5rem; }
textarea.code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.82rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 1rem; }
.form-grid .wide { grid-column: 1 / -1; }
.checkbox { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; cursor: pointer; }
.checkbox input { width: auto; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: #eef6fd url("../images/background.jpg") center / cover no-repeat;
}
.login-card {
  position: relative; width: 100%; max-width: 400px; background: var(--surface); border-radius: 12px;
  padding: 2rem; box-shadow: 0 10px 36px rgba(31, 66, 117, 0.18); border: 1px solid #dde6f2;
}
.login-card .brand { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; margin-bottom: 1.5rem; text-align: center; }
.login-card .brand p { color: var(--muted); margin: 0; font-size: 0.9rem; }
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.tabs button {
  flex: 1; padding: 0.6rem; background: none; border: none; border-bottom: 2px solid transparent;
  font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: 100vh; }
.shell > * { min-width: 0; }
.sidebar {
  background: var(--accent); color: #fff; padding: 1.25rem 0.85rem;
  display: flex; flex-direction: column; gap: 1.5rem;
  position: sticky; top: 0; height: 100vh;
}
.logo { font-size: 1.15rem; font-weight: 700; padding: 0 0.5rem; color: #fff; text-decoration: none; }
.logo span { color: #bcd0ee; }
.logo:hover { color: #fff; }
.nav { display: flex; flex-direction: column; gap: 0.2rem; }
.nav a {
  display: flex; align-items: center; gap: 0.65rem; padding: 0.55rem 0.7rem; border-radius: var(--radius);
  color: rgba(255, 255, 255, 0.85); text-decoration: none; font-weight: 500; font-size: 0.93rem;
}
.nav a:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, 0.18); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #fff; }
.nav a:focus-visible { outline: 3px solid rgba(255, 255, 255, 0.6); outline-offset: 1px; }
.sidebar-footer { margin-top: auto; padding: 0 0.5rem; font-size: 0.82rem; color: rgba(255, 255, 255, 0.8); display: flex; flex-direction: column; align-items: flex-start; gap: 0.6rem; }
.user-email { word-break: break-all; }
.btn-sidebar { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.5); }
.btn-sidebar:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }

/* Language switcher (sidebar = on accent; light = on white card) */
.lang-switch { display: inline-flex; border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 999px; overflow: hidden; }
.lang-switch button {
  background: transparent; border: none; color: #fff; font: inherit; font-size: 0.75rem; font-weight: 700;
  padding: 0.25rem 0.7rem; cursor: pointer; letter-spacing: 0.04em;
}
.lang-switch button[aria-pressed="true"] { background: #fff; color: var(--accent); }
.lang-switch button:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.lang-switch-light { border-color: var(--border); position: absolute; top: 1rem; right: 1rem; }
.lang-switch-light button { color: var(--muted); }
.lang-switch-light button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.lang-switch-light button:focus-visible { outline-color: var(--accent); }
/* Content is centered in the area next to the sidebar. */
.main { padding: 2rem 2.5rem; max-width: 1200px; width: 100%; margin: 0 auto; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-header p { color: var(--muted); margin: 0; }

/* ---------- Cards, tables, badges ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.card-header h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
td { padding: 0.65rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfaf8; }
.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }
.table-wrap { overflow-x: auto; }
.filename { font-weight: 600; word-break: break-word; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.76rem; font-weight: 600; white-space: nowrap; }
.badge-neutral { background: var(--neutral-bg); color: #3d3d3d; }
.badge-info { background: var(--accent-tint); color: var(--accent); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }

/* ---------- Dropzone ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem; text-align: center;
  padding: 2rem 1rem; border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--accent); cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-tint); }
.dropzone p { margin: 0; color: var(--text); }
.dropzone .small { color: var(--muted); }

/* ---------- Empty / loading states ---------- */
.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.6rem; padding: 2.5rem 1rem; color: var(--muted); }
.state h3 { color: var(--text); margin: 0.25rem 0 0; }
.state p { margin: 0; max-width: 420px; }
.state .icon { color: var(--accent); }

/* ---------- Template picker ---------- */
.template-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 0.9rem; margin-bottom: 1.5rem; }
.template-option {
  display: flex; gap: 0.9rem; align-items: center; text-align: left; padding: 1rem; font: inherit; color: var(--text);
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.template-option:hover { border-color: var(--accent); }
.template-option[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-tint); }
.template-option strong { display: block; margin-bottom: 0.15rem; }
.template-option > div > span { font-size: 0.83rem; color: var(--muted); }

/* ---------- Agent timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.5rem; border-left: 2px solid var(--border); margin-left: 0.4rem; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 0.3rem; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.timeline li.error::before { background: var(--danger); }
.timeline li.waiting::before { background: var(--warning); }
.timeline .step-title { font-weight: 600; }
details summary { cursor: pointer; color: var(--accent); font-size: 0.82rem; }
pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem; overflow-x: auto; font-size: 0.8rem; margin: 0.4rem 0 0; white-space: pre-wrap; word-break: break-word; }

.approval { border: 2px solid var(--warning); background: var(--warning-bg); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.approval-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.75rem; }
.approval-header .icon { color: var(--warning); }
.result-banner { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.25rem; border-radius: var(--radius); margin-bottom: 1.25rem; }
.result-banner.success { background: var(--success-bg); }
.result-banner.danger { background: var(--danger-bg); color: var(--danger); }
.result-banner.danger .icon { color: var(--danger); }
.result-banner.neutral { background: var(--neutral-bg); }
.result-banner p { margin: 0; color: var(--text); }

.back { display: inline-flex; align-items: center; gap: 0.3rem; margin-bottom: 1rem; font-size: 0.88rem; text-decoration: none; font-weight: 600; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 1.25rem; bottom: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 50; max-width: 380px; }
.toast { padding: 0.75rem 1rem; border-radius: var(--radius); background: #1f2328; color: #fff; font-size: 0.9rem; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); animation: toast-in 0.2s ease-out; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.form-error { background: var(--danger-bg); color: var(--danger); padding: 0.6rem 0.8rem; border-radius: var(--radius); font-size: 0.88rem; margin-bottom: 0.9rem; }

@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 0.85rem; gap: 0.75rem; }
  .nav a.active { box-shadow: inset 0 -3px 0 #fff; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .sidebar-footer { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 0; }
  .main { padding: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  .spin, .toast { animation: none; }
}

/* Main receives programmatic focus on navigation (for screen readers); no visible ring needed. */
.main:focus { outline: none; }
a.filename { text-decoration: none; }
a.filename:hover { text-decoration: underline; }
.template-option > div > span { display: block; line-height: 1.4; }
.mini-table th, .mini-table td { padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.mini-table { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.table-wrap > table { min-width: 640px; }

/* ---------- Inline validation ---------- */
input.invalid, textarea.invalid, select.invalid { border-color: var(--danger); background: #fffafa; }
.field-error { color: var(--danger); font-size: 0.8rem; margin-top: 0.3rem; display: flex; gap: 0.3rem; }
.field-error::before { content: "⚠"; }

/* ---------- Confirmation dialog ---------- */
.dialog {
  border: none; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 2rem));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); color: var(--text);
}
.dialog::backdrop { background: rgba(10, 22, 48, 0.45); }
.dialog-body { display: flex; gap: 1rem; padding: 1.5rem 1.5rem 1rem; }
.dialog-body h2 { margin: 0 0 0.35rem; }
.dialog-body p { margin: 0; color: var(--muted); }
.dialog-icon {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--danger-bg); color: var(--danger); font-weight: 800; font-size: 1.2rem;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 1rem 1.5rem; background: var(--bg); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover:not(:disabled) { background: #a51b18; }

/* ---------- Toast close button ---------- */
.toast { display: flex; align-items: flex-start; gap: 0.75rem; }
.toast span { flex: 1; }
.toast-close { background: none; border: none; color: inherit; font-size: 1.1rem; line-height: 1; cursor: pointer; opacity: 0.8; padding: 0; }
.toast-close:hover { opacity: 1; }

/* ---------- Toolbar, chips and filters ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip {
  padding: 0.35rem 0.85rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  font: inherit; font-size: 0.85rem; font-weight: 600; color: var(--text); cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip:focus-visible { outline: 3px solid rgba(43, 87, 151, 0.35); outline-offset: 2px; }
input.search { max-width: 280px; padding-left: 2rem; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23555b63' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 4 4'/%3E%3C/svg%3E") 0.6rem center no-repeat; }
.filters { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input.search { flex: 1; min-width: 200px; max-width: 360px; }
.filters select { width: auto; min-width: 170px; }
.filter-count { margin-left: auto; }

/* ---------- Template gallery ---------- */
.template-option { align-items: flex-start; transition: border-color 0.15s, box-shadow 0.15s; }
.template-option:hover { box-shadow: var(--shadow); }
.template-category { display: inline-block !important; font-size: 0.7rem !important; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent) !important; margin-bottom: 0.15rem; }
.template-icon { display: inline-grid; place-items: center; color: var(--accent); flex-shrink: 0; }
.cell-with-icon { display: flex; align-items: center; gap: 0.6rem; }

/* ---------- Generate form ---------- */
.form-title { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; margin-bottom: 0.25rem; }
.form-title h2 { margin: 0; }
.form-title p { margin: 0; }
.prefill { max-width: 460px; }
.form-section { border: none; border-top: 1px solid var(--border); padding: 1rem 0 0; margin: 1rem 0 0; }
.form-section legend { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); padding: 0 0.5rem 0 0; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }

.rows-editor table { min-width: 0 !important; }
.rows-editor th { padding: 0.4rem 0.35rem; }
.rows-editor td { padding: 0.3rem 0.35rem; border-bottom: none; }
.rows-editor input { padding: 0.4rem 0.5rem; font-size: 0.88rem; }
.rows-editor .col-wide { width: 45%; }
.rows-editor .row-total { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.row-remove { padding: 0.25rem 0.55rem; }
.rows-footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 0.5rem; font-size: 0.9rem; }

/* ---------- Style picker ---------- */
.style-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.style-option {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; text-align: left; font: inherit; color: var(--text);
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.style-option:hover { border-color: var(--accent); }
.style-option[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-tint); }
.style-option strong { display: block; }
.style-option small { color: var(--muted); }
.style-sample { width: 56px; height: 64px; flex-shrink: 0; background: #fff; border: 1px solid var(--border); border-radius: 4px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.style-sample-title { font-weight: 700; font-size: 0.95rem; line-height: 1; }
.style-sample-bar { height: 6px; border-radius: 1px; }
.style-sample-line { height: 3px; background: #ccc; border-radius: 1px; }
.style-sample-line.short { width: 60%; }
.style-classic .style-sample-title { font-family: Georgia, "Times New Roman", serif; color: #000; text-align: center; }
.style-classic .style-sample-bar { background: #eee; }
.style-modern .style-sample-title { color: var(--accent); }
.style-modern .style-sample-bar { background: var(--accent); }
.style-minimal .style-sample-title { color: #444; font-weight: 600; font-size: 0.85rem; }
.style-minimal .style-sample-bar { background: #f2f2f2; }

.pdf-preview { width: 100%; height: 720px; border: 1px solid var(--border); border-radius: 6px; background: #eee; }

@media (max-width: 800px) {
  .main { padding: 1.25rem; }
  .filter-count { margin-left: 0; }
  input.search { max-width: none; }
}
