:root {
  --navy: #0d1b2a;
  --navy-2: #18314d;
  --gold: #d8a72f;
  --gold-light: #f4d881;
  --text: #142033;
  --muted: #667085;
  --line: #dfe5ec;
  --panel: #ffffff;
  --bg: #f3f6fa;
  --success: #16855b;
  --danger: #b42318;
  --shadow: 0 12px 34px rgba(20, 32, 51, .07);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 26px;
  background:
    radial-gradient(circle at 85% 15%, rgba(216,167,47,.18), transparent 30%),
    radial-gradient(circle at 15% 85%, rgba(55,93,129,.22), transparent 35%),
    linear-gradient(135deg, #0d1b2a, #18314d);
}
.auth-brand {
  position: fixed;
  top: 28px;
  left: 34px;
  display: flex;
  gap: 13px;
  align-items: center;
  color: white;
}
.auth-brand img { width: 58px; height: 58px; border-radius: 12px; }
.auth-brand h1 { font-size: 20px; margin: 0; letter-spacing: .5px; }
.auth-brand p { color: #c7d5e4; font-size: 12px; margin: 5px 0 0; }
.auth-card {
  width: min(440px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 28px 80px rgba(0,0,0,.3);
}
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #f2f4f7; padding: 5px; border-radius: 11px; margin-bottom: 22px; }
.auth-tab { border: 0; background: transparent; border-radius: 8px; padding: 10px; color: var(--muted); font-weight: 700; }
.auth-tab.active { color: var(--text); background: #fff; box-shadow: 0 3px 10px rgba(20,32,51,.09); }
#authForm { display: flex; flex-direction: column; gap: 15px; }
#authForm label { font-size: 12px; font-weight: 700; color: #344054; }
#authForm input { width: 100%; height: 44px; margin-top: 7px; border: 1px solid #cfd7e1; border-radius: 10px; padding: 0 12px; outline: none; }
#authForm input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(216,167,47,.14); }
.auth-message { min-height: 20px; margin: 15px 0 0; font-size: 12px; color: var(--danger); }
.auth-message.ok { color: var(--success); }
.auth-note { font-size: 11px; color: var(--muted); line-height: 1.5; margin: 9px 0 0; }

.app-shell { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: linear-gradient(180deg, #0c1928 0%, #10243a 100%);
  color: #fff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  box-shadow: 8px 0 30px rgba(8, 19, 31, .12);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 28px; border-bottom: 1px solid rgba(255,255,255,.09); }
.brand-mark { width: 54px; height: 54px; border-radius: 12px; object-fit: cover; box-shadow: 0 10px 24px rgba(216,167,47,.2); }
.brand-name { font-size: 16px; font-weight: 800; letter-spacing: .3px; }
.brand-sub { color: #aebed0; font-size: 12px; margin-top: 3px; }
nav { display: flex; flex-direction: column; gap: 8px; margin-top: 24px; }
.nav-item {
  border: 0; color: #c8d5e3; background: transparent; padding: 13px 14px;
  display: flex; align-items: center; gap: 12px; border-radius: 10px; text-align: left;
  transition: .18s ease;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(216,167,47,.16); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav-icon { width: 22px; font-size: 17px; color: var(--gold-light); }
.sidebar-note { margin-top: auto; background: rgba(255,255,255,.055); border: 1px solid rgba(255,255,255,.075); padding: 15px; border-radius: 12px; display: flex; flex-direction: column; gap: 7px; }
.sidebar-note strong { color: var(--gold-light); font-size: 12px; }
.sidebar-note span { color: #aebed0; font-size: 11.5px; line-height: 1.5; }

.main-content { min-width: 0; padding: 0 30px 38px; }
.topbar {
  position: sticky; top: 0; z-index: 10; background: rgba(243,246,250,.94); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: space-between; padding: 22px 0 17px; border-bottom: 1px solid rgba(223,229,236,.85);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar h1 { margin: 0; font-size: 27px; letter-spacing: -.4px; }
.topbar p { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; background: #fff; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.status-dot { width: 8px; height: 8px; background: #9aa4b2; border-radius: 50%; }
.status-pill.ok .status-dot { background: var(--success); box-shadow: 0 0 0 4px rgba(22,133,91,.1); }
.status-pill.bad .status-dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(180,35,24,.1); }
.account-btn, .icon-btn { border: 1px solid var(--line); background: #fff; color: #344054; border-radius: 9px; padding: 8px 11px; font-size: 12px; font-weight: 700; }
.icon-btn { font-size: 19px; padding: 7px 10px; }
.mobile-only { display: none; }

.view { display: none; padding-top: 24px; }
.view.active { display: block; }
.step-grid { display: grid; grid-template-columns: minmax(520px, 1.5fr) minmax(330px, .85fr); gap: 22px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.upload-panel, .letter-panel, .result-panel, .cases-panel, .settings-grid .panel { padding: 22px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 3px 0 0; font-size: 18px; }
.step-label { color: #8b6a12; font-weight: 800; font-size: 10.5px; letter-spacing: 1.2px; }
.text-btn { border: 0; background: transparent; color: #7d5d0a; font-weight: 700; font-size: 12px; }
.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.upload-card {
  min-height: 104px; background: #fbfcfe; border: 1px dashed #cfd7e1; border-radius: 13px;
  padding: 15px; display: grid; grid-template-columns: 42px minmax(0,1fr); grid-template-rows: auto auto; column-gap: 12px; text-align: left;
  transition: .18s ease;
}
.upload-card:hover { border-color: var(--gold); background: #fffdf8; transform: translateY(-1px); }
.upload-card.has-file { border-style: solid; border-color: #9dcdb9; background: #f7fcfa; }
.upload-icon { grid-row: 1 / span 2; width: 42px; height: 42px; display: grid; place-items: center; background: #eef3f8; border-radius: 10px; font-size: 20px; }
.upload-copy { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.upload-copy strong { font-size: 13.5px; }
.upload-copy span { font-size: 11.5px; color: var(--muted); }
.file-state { align-self: end; color: #7d5d0a; font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stored-files-notice { margin-top: 13px; border: 1px solid #bad4e8; background: #f3f9fd; color: #35546c; border-radius: 10px; padding: 10px 12px; font-size: 11.5px; line-height: 1.45; }

.field-label { display: block; font-size: 12px; font-weight: 700; margin: 13px 0 7px; color: #344054; }
.field-label span { color: #8c96a3; font-weight: 500; }
.select-input, .text-input, .instruction-box, .letter-editor, #fileName {
  width: 100%; border: 1px solid #cfd7e1; border-radius: 10px; background: #fff; color: var(--text); outline: none; transition: .16s ease;
}
.select-input, .text-input, #fileName { height: 42px; padding: 0 12px; }
.instruction-box { min-height: 138px; resize: vertical; padding: 11px 12px; line-height: 1.45; }
.select-input:focus, .text-input:focus, .instruction-box:focus, .letter-editor:focus, #fileName:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(216,167,47,.12); }
.primary-btn {
  border: 0; border-radius: 10px; background: linear-gradient(135deg, #18314d, #0c1b2b); color: #fff; font-weight: 800;
  padding: 13px 16px; display: flex; align-items: center; justify-content: center; gap: 9px; box-shadow: 0 10px 20px rgba(13,27,42,.14);
}
.letter-panel .primary-btn, .auth-card .primary-btn { width: 100%; margin-top: 17px; }
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: .55; cursor: not-allowed; }
.primary-btn.compact { width: auto; padding: 10px 16px; margin-top: 0; }
.secondary-btn { border: 1px solid #cfd7e1; background: #fff; color: #25364b; border-radius: 9px; padding: 9px 12px; font-size: 12px; font-weight: 700; }
.secondary-btn:hover { border-color: var(--gold); background: #fffdf7; }
.danger-btn { color: var(--danger); margin-top: 18px; }
.helper-text, .settings-note { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin-top: 12px; }
.result-panel { margin-top: 22px; }
.result-heading { align-items: center; margin-bottom: 13px; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.editor-toolbar { border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0; background: #f8fafc; display: grid; grid-template-columns: minmax(220px, 1fr) auto; align-items: center; gap: 16px; padding: 9px 11px; }
#fileName { height: 34px; max-width: 430px; font-size: 12px; }
#wordCount { color: var(--muted); font-size: 11.5px; }
.letter-editor { min-height: 560px; resize: vertical; border-radius: 0 0 10px 10px; padding: 28px 32px; line-height: 1.6; font-family: Georgia, "Times New Roman", serif; font-size: 14px; }

.settings-grid { display: grid; grid-template-columns: 1.1fr .8fr; gap: 22px; }
.settings-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid label { font-size: 12px; font-weight: 700; color: #344054; }
.form-grid label input, .form-grid label textarea { margin-top: 7px; font-weight: 400; }
.span-2 { grid-column: 1 / -1; }
.small-textarea { height: 76px; padding: 10px 12px; resize: vertical; }
.account-row { border-bottom: 1px solid var(--line); padding: 13px 0; display: flex; justify-content: space-between; gap: 14px; font-size: 12px; }
.account-row span { color: var(--muted); }
.account-row strong { text-align: right; word-break: break-word; }

.cases-list { display: flex; flex-direction: column; gap: 10px; }
.case-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: #fbfcfe; }
.case-card:hover { border-color: #c5ab64; background: #fffef9; }
.case-title { font-weight: 800; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-meta { margin-top: 5px; color: var(--muted); font-size: 11.5px; }
.case-actions { display: flex; gap: 7px; }
.empty-state { padding: 45px 20px; text-align: center; color: var(--muted); border: 1px dashed #cfd7e1; border-radius: 12px; }

.toast { position: fixed; right: 26px; bottom: 24px; z-index: 80; background: #172536; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.18); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .22s ease; max-width: min(420px, calc(100vw - 40px)); font-size: 12.5px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #9f2f2f; }
.loading-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(10,22,35,.45); backdrop-filter: blur(4px); display: none; place-items: center; padding: 20px; }
.loading-overlay.show { display: grid; }
.loading-card { background: #fff; width: min(390px, 100%); border-radius: 16px; padding: 29px; text-align: center; box-shadow: 0 24px 70px rgba(0,0,0,.22); }
.loading-card h3 { margin: 15px 0 7px; }
.loading-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.spinner { width: 44px; height: 44px; margin: auto; border: 4px solid #e7ecf2; border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sidebar-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; }

@media (max-width: 1180px) {
  .step-grid, .settings-grid { grid-template-columns: 1fr; }
  .app-shell { grid-template-columns: 235px minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .mobile-only { display: inline-flex; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; width: 270px; transform: translateX(-102%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding: 0 15px 28px; }
  .topbar { padding: 14px 0; }
  .topbar h1 { font-size: 20px; }
  .topbar p { display: none; }
  .status-pill { display: none; }
  .account-btn { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .view { padding-top: 15px; }
  .upload-grid { grid-template-columns: 1fr; }
  .upload-panel, .letter-panel, .result-panel, .cases-panel, .settings-grid .panel { padding: 16px; }
  .result-heading { align-items: flex-start; flex-direction: column; }
  .result-actions { justify-content: flex-start; }
  .letter-editor { min-height: 440px; padding: 20px 17px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .case-card { grid-template-columns: 1fr; }
  .case-actions { justify-content: flex-start; }
}

@media (max-width: 520px) {
  .auth-brand { position: static; margin-bottom: 18px; }
  .auth-screen { align-content: center; }
  .auth-card { padding: 21px; }
  .topbar-right .account-btn { display: none; }
  .editor-toolbar { grid-template-columns: 1fr; gap: 7px; }
  #fileName { max-width: none; }
}
