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

:root {
  --bg:        #f5f5f5;
  --surface:   #ffffff;
  --border:    #e0e0e0;
  --text:      #1a1a1a;
  --muted:     #6b6b6b;
  --accent:    #2563eb;
  --accent-hv: #1d4ed8;
  --danger:    #dc2626;
  --success:   #16a34a;
  --radius:    10px;
  --shadow:    0 1px 4px rgba(0,0,0,.08);
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Screens ──────────────────────────────────────────────────── */
.screen { display: none; min-height: 100dvh; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* ── LOGIN ────────────────────────────────────────────────────── */
#screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
#screen-login.active { display: flex; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 28px 32px;
}

.logo {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--accent);
}

.tagline {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 28px;
}

.auth-switch {
  margin-top: 18px;
  font-size: .85rem;
  color: var(--muted);
  text-align: center;
}
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

.hint {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 16px;
}

/* ── APP SHELL ────────────────────────────────────────────────── */
#screen-app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
#screen-app.active { display: flex; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--accent);
}

/* ── TABS ─────────────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 12px 8px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

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

.tab-content { display: none; padding: 16px; flex: 1; }
.tab-content.active { display: block; }

/* ── CARDS ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px;
  margin-bottom: 12px;
}

.section-title {
  font-size: .875rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 16px;
}

/* ── FIELDS ───────────────────────────────────────────────────── */
.auth-form .field,
.field {
  margin-bottom: 14px;
}

label, .field-label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"] {
  width: 100%;
  padding: 10px 12px;
  font-size: .95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  background: var(--surface);
}

/* ── SELECT ───────────────────────────────────────────────────── */
.select-wrap { position: relative; }

.select-wrap::after {
  content: "▾";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted);
  font-size: .8rem;
}

select {
  width: 100%;
  padding: 10px 32px 10px 12px;
  font-size: .95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  appearance: none;
  cursor: pointer;
  transition: border-color .15s;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── SEARCHABLE COMBOBOX ──────────────────────────────────────── */
.combobox { position: relative; }

.combobox-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.combobox-input-wrap input {
  padding-right: 32px; /* room for clear button */
}

.combobox-clear {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
.combobox-clear:hover { color: var(--text); }

.combobox-list {
  position: absolute;
  z-index: 100;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
  max-height: 220px;
  overflow-y: auto;
  list-style: none;
  padding: 4px 0;
  margin: 0;
}

.combobox-list li {
  padding: 10px 14px;
  font-size: .92rem;
  cursor: pointer;
  transition: background .1s;
}

.combobox-list li:hover,
.combobox-list li[aria-selected="true"] {
  background: #eff6ff;
  color: var(--accent);
}

.combobox-list li.combobox-empty {
  color: var(--muted);
  cursor: default;
  font-size: .85rem;
}
.combobox-list li.combobox-empty:hover { background: none; color: var(--muted); }

/* ── BUTTONS ──────────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 12px;
  margin-top: 6px;
  font-size: .95rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.btn-primary:hover  { background: var(--accent-hv); }
.btn-primary:active { opacity: .85; }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.btn-ghost {
  padding: 6px 10px;
  font-size: .8rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-ghost:hover { color: var(--danger); border-color: var(--danger); }

/* ── MESSAGES ─────────────────────────────────────────────────── */
.error-msg {
  font-size: .85rem;
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 9px 12px;
  margin-bottom: 10px;
}

.success-msg {
  font-size: .85rem;
  color: var(--success);
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 9px 12px;
  margin-bottom: 10px;
}

.success-msg a {
  color: var(--success);
  font-weight: 600;
}

/* ── HISTORY LIST ─────────────────────────────────────────────── */
.loading-state, .empty-state {
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
  padding: 48px 16px;
}

.doc-list { display: flex; flex-direction: column; gap: 10px; }

.doc-item {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.doc-info { flex: 1; min-width: 0; }

.doc-name {
  font-size: .95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-size: .78rem;
  color: var(--muted);
  margin-top: 2px;
}

.btn-download {
  flex-shrink: 0;
  padding: 7px 14px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 1px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.btn-download:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Spinner inside buttons ───────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }
