:root {
  --bg: #08132b;
  --bg-soft: #0d1b36;
  --panel: #112141;
  --panel-2: #15294e;
  --border: #29426f;
  --text: #f5f8ff;
  --muted: #9db0d1;
  --accent: #4d78ff;
  --accent-2: #41d7d0;
  --danger: #ff6875;
  --success: #49d98a;
  --warning: #ffd166;
  --shadow: 0 18px 45px rgba(0, 0, 0, .28);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 85% -10%, rgba(65, 215, 208, .14), transparent 28rem),
    radial-gradient(circle at 0% 20%, rgba(77, 120, 255, .17), transparent 26rem),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .52; cursor: not-allowed; }
input, select {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #0b1934;
  color: var(--text);
  padding: 0 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(65, 215, 208, .12); }
label { display: block; margin: 15px 0 7px; font-size: .91rem; font-weight: 650; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(1.75rem, 4vw, 2.25rem); letter-spacing: -.03em; }
h2 { margin-bottom: 0; font-size: 1.18rem; }
h3 { margin-bottom: 4px; }
[hidden] { display: none !important; }

.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: var(--danger); color: #21070b; text-align: center; padding: 7px 12px; font-weight: 750;
}
.eyebrow { margin-bottom: 4px; color: var(--accent-2); font-size: .74rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: .84rem; line-height: 1.4; }
.form-error { margin: 14px 0 0; padding: 11px 12px; border: 1px solid rgba(255,104,117,.55); border-radius: 12px; background: rgba(255,104,117,.1); color: #ffc5cb; }

.login-layout { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(100%, 430px); padding: 30px; border: 1px solid var(--border); border-radius: 26px;
  background: linear-gradient(160deg, rgba(21,41,78,.98), rgba(9,24,52,.98)); box-shadow: var(--shadow);
}
.login-logo { width: 72px; height: 72px; border-radius: 20px; margin-bottom: 16px; }
.check-row { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--muted); }
.check-row input { width: 20px; min-height: 20px; accent-color: var(--accent); }
.primary, .secondary, .passkey-button, .filter-button, .small-button, .camera-label {
  border: 0; border-radius: 13px; min-height: 50px; padding: 0 16px; font-weight: 760;
}
.primary { width: 100%; margin-top: 12px; background: linear-gradient(120deg, var(--accent-2), var(--accent)); color: #061229; }
.secondary { background: #1b3158; color: var(--text); border: 1px solid var(--border); }
.passkey-button { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; background: #f3f6ff; color: #0a1530; }
.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: .8rem; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--border); }

.app-shell { min-height: 100vh; min-height: 100dvh; }
.app-header {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between;
  min-height: 68px; padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  background: rgba(8,19,43,.88); border-bottom: 1px solid rgba(41,66,111,.65); backdrop-filter: blur(18px);
}
.brand-block { display: flex; align-items: center; gap: 11px; }
.brand-block img { width: 38px; height: 38px; border-radius: 11px; }
.brand-block strong, .brand-block span { display: block; }
.brand-block strong { font-size: .98rem; }
.brand-block span { margin-top: 2px; color: var(--muted); font-size: .77rem; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); font-size: 1.35rem; }
.content { width: min(100%, 1080px); margin: 0 auto; padding: 22px 18px calc(98px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; animation: enter .18s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.view-heading { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.view-heading h1 { margin-bottom: 0; }
.count-badge { min-width: 40px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 999px; text-align: center; color: var(--accent-2); background: var(--panel); font-weight: 800; }

.panel { border: 1px solid var(--border); border-radius: var(--radius); background: rgba(17,33,65,.88); box-shadow: 0 12px 34px rgba(0,0,0,.14); padding: 17px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.text-button { border: 0; background: transparent; color: var(--accent-2); font-weight: 700; padding: 8px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { min-height: 108px; padding: 16px; border: 1px solid var(--border); border-radius: 17px; background: linear-gradient(145deg, var(--panel-2), var(--panel)); }
.stat-card span { display: block; color: var(--muted); font-size: .83rem; }
.stat-card strong { display: block; margin-top: 8px; font-size: 1.65rem; letter-spacing: -.03em; }

.search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-bottom: 11px; }
.search-box { margin: 0; display: flex; align-items: center; gap: 8px; min-height: 52px; border: 1px solid var(--border); border-radius: 14px; background: #0b1934; padding-left: 13px; }
.search-box:focus-within { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(65,215,208,.12); }
.search-box input { min-height: 49px; border: 0; background: transparent; padding-left: 0; box-shadow: none; }
.search-box.full { margin-bottom: 14px; }
.filter-button { position: relative; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.filter-button span { display: inline-grid; place-items: center; min-width: 21px; height: 21px; margin-left: 5px; padding: 0 5px; border-radius: 999px; background: var(--accent-2); color: #061229; font-size: .74rem; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 12px; }
.filter-chip { border: 1px solid #3f5f96; border-radius: 999px; background: #18315d; color: var(--text); padding: 7px 10px; font-size: .79rem; }

.document-list { display: grid; gap: 10px; }
.document-list.compact { gap: 8px; }
.document-card { position: relative; border: 1px solid var(--border); border-radius: 16px; background: linear-gradient(145deg, rgba(21,41,78,.98), rgba(14,29,57,.98)); padding: 15px; }
.document-card.selected { border-color: var(--accent-2); }
.document-card-head { display: grid; grid-template-columns: auto 1fr auto; gap: 11px; align-items: start; }
.file-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: #213b69; color: var(--accent-2); font-size: .72rem; font-weight: 850; text-transform: uppercase; }
.document-title { margin: 0; font-size: .98rem; line-height: 1.35; overflow-wrap: anywhere; }
.document-category { margin: 4px 0 0; color: var(--muted); font-size: .78rem; }
.star-button, .more-button { width: 38px; height: 38px; border: 0; border-radius: 11px; background: rgba(8,19,43,.58); color: #d9e2f6; font-size: 1.3rem; }
.star-button.active { color: var(--warning); }
.document-meta { display: flex; flex-wrap: wrap; gap: 8px 12px; margin: 12px 0 0 53px; color: var(--muted); font-size: .77rem; }
.document-actions { display: grid; grid-template-columns: 1fr auto; gap: 9px; margin-top: 13px; }
.document-actions button { min-height: 42px; border: 1px solid var(--border); border-radius: 11px; background: #19305a; color: var(--text); font-weight: 700; }
.document-actions .more-button { width: 48px; font-size: 1rem; }
.empty-state { padding: 34px 18px; border: 1px dashed var(--border); border-radius: var(--radius); text-align: center; color: var(--muted); }
.loading-row { padding: 28px; text-align: center; color: var(--muted); }

.form-panel { max-width: 650px; }
.form-panel > label:first-child { margin-top: 0; }
.category-picker { min-width: 0; margin: 16px 0 0; padding: 14px; border: 1px solid var(--border); border-radius: 15px; background: rgba(8,19,43,.35); }
.category-picker legend { padding: 0 7px; color: var(--text); font-size: .88rem; font-weight: 800; }
.category-picker label:first-of-type { margin-top: 0; }
.category-picker [hidden] { display: none !important; }
.category-selection { margin: 10px 2px 0; font-size: .78rem; }
input[type="file"] { padding: 11px; min-height: 58px; }
.camera-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 9px; }
.camera-label { display: inline-flex; align-items: center; justify-content: center; margin: 0; min-height: 43px; background: #1d3560; border: 1px solid var(--border); }
#upload-status { margin: 12px 0 0; color: var(--muted); }
#upload-status.success { color: var(--success); }
#upload-status.error { color: #ffc5cb; }

.account-panel { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.avatar { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #061229; font-weight: 900; font-size: 1.2rem; }
.account-panel p { margin: 4px 0 0; }
.menu-list { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
.menu-list button { width: 100%; min-height: 56px; display: flex; align-items: center; justify-content: space-between; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text); padding: 0 16px; text-align: left; }
.menu-list button:last-child { border-bottom: 0; }
.danger-row { color: #ff9aa4 !important; }
.version-note { margin: 16px 4px; color: var(--muted); font-size: .78rem; text-align: center; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; display: grid; grid-template-columns: repeat(5,1fr);
  min-height: 68px; padding: 7px 6px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(41,66,111,.8);
  background: rgba(8,19,43,.94); backdrop-filter: blur(18px);
}
.bottom-nav button { min-width: 0; border: 0; border-radius: 12px; background: transparent; color: var(--muted); padding: 5px 2px; }
.bottom-nav button span, .bottom-nav button small { display: block; }
.bottom-nav button span { font-size: 1.22rem; line-height: 1; }
.bottom-nav button small { margin-top: 5px; font-size: .68rem; }
.bottom-nav button.active { color: var(--accent-2); background: rgba(65,215,208,.09); }

.sheet-dialog, .full-dialog { border: 0; padding: 0; background: transparent; color: var(--text); }
.sheet-dialog { width: 100%; max-width: none; margin: auto 0 0; }
.sheet-dialog::backdrop, .full-dialog::backdrop { background: rgba(2,8,20,.75); backdrop-filter: blur(4px); }
.sheet-card { width: min(100%, 620px); max-height: 86vh; overflow: auto; margin: 0 auto; padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); border: 1px solid var(--border); border-bottom: 0; border-radius: 24px 24px 0 0; background: #0e1d3a; box-shadow: 0 -22px 55px rgba(0,0,0,.42); }
.sheet-handle { width: 48px; height: 5px; margin: 2px auto 14px; border-radius: 999px; background: #48638e; }
.sheet-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; margin-top: 20px; }
.sheet-actions button { margin: 0; }
.action-menu { margin-top: 14px; }

.install-dialog { width: min(calc(100% - 28px), 470px); max-width: 470px; border: 0; padding: 0; background: transparent; color: var(--text); }
.install-dialog::backdrop { background: rgba(2,8,20,.78); backdrop-filter: blur(5px); }
.install-card { padding: 24px 21px 20px; border: 1px solid var(--border); border-radius: 24px; background: linear-gradient(155deg, #14294d, #0b1933); box-shadow: 0 28px 70px rgba(0,0,0,.48); text-align: center; }
.install-icon { width: 72px; height: 72px; border-radius: 18px; box-shadow: 0 12px 28px rgba(0,0,0,.28); }
.install-card .eyebrow { margin-top: 14px; }
.install-card h2 { margin: 5px 0 10px; font-size: 1.38rem; }
.install-card > p { line-height: 1.5; }
.install-steps { margin: 16px 0 0; padding: 14px 14px 14px 36px; border: 1px solid var(--border); border-radius: 14px; background: rgba(8,19,43,.48); text-align: left; }
.install-steps li { margin: 7px 0; line-height: 1.42; }
.install-actions { display: grid; grid-template-columns: 1fr 1.25fr; gap: 10px; margin-top: 20px; }
.install-actions button { margin: 0; min-height: 48px; }
.install-once-note { margin: 13px 0 0 !important; font-size: .73rem; }

.full-dialog { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; }
.full-dialog-card { min-height: 100vh; min-height: 100dvh; background: var(--bg); padding: max(12px,env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
.full-dialog-card > header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.full-dialog-card > header h2 { font-size: 1.45rem; }
.security-section { margin-bottom: 14px; }
.security-section .panel-heading { align-items: flex-start; }
.small-button { min-height: 40px; padding: 0 12px; background: var(--accent-2); color: #061229; white-space: nowrap; }
.security-list { display: grid; gap: 9px; }
.security-item { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 13px; background: #0c1932; }
.security-item strong, .security-item span { display: block; }
.security-item span { margin-top: 3px; color: var(--muted); font-size: .76rem; }
.security-item button { min-width: 42px; min-height: 38px; border: 1px solid var(--border); border-radius: 10px; background: #1b3158; color: #ffb6bd; }
.current-badge { display: inline-block !important; width: fit-content; margin-top: 5px !important; border-radius: 999px; background: rgba(73,217,138,.14); color: var(--success) !important; padding: 3px 7px; }

.busy-overlay { position: fixed; inset: 0; z-index: 1200; display: grid; place-items: center; align-content: center; gap: 12px; background: rgba(4,11,27,.88); text-align: center; }
.spinner { width: 42px; height: 42px; border: 4px solid #2b426b; border-top-color: var(--accent-2); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 1300; transform: translateX(-50%); width: min(calc(100% - 32px), 520px); padding: 12px 14px; border: 1px solid #426494; border-radius: 13px; background: #172c51; box-shadow: var(--shadow); text-align: center; }

@media (min-width: 760px) {
  .content { padding-top: 30px; }
  .stats-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .document-list { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .document-list.compact { grid-template-columns: 1fr; }
  .bottom-nav { left: 50%; right: auto; width: min(720px,calc(100% - 32px)); transform: translateX(-50%); bottom: 14px; border: 1px solid var(--border); border-radius: 20px; padding-bottom: 7px; box-shadow: var(--shadow); }
  .content { padding-bottom: 110px; }
  .full-dialog-card { width: min(760px,100%); margin: 0 auto; }
}

@media (max-width: 430px) {
  .login-layout { padding: 14px; }
  .login-card { padding: 23px 18px; border-radius: 22px; }
  .content { padding-left: 12px; padding-right: 12px; }
  .app-header { padding-left: 12px; padding-right: 12px; }
  .brand-block strong { font-size: .9rem; }
  .document-meta { margin-left: 0; }
  .panel-heading { align-items: flex-start; }
  .security-section .panel-heading { display: block; }
  .security-section .small-button { margin-top: 10px; width: 100%; }
}
