/* ── Doc21 — style.css ── */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --sidebar-w: 280px;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #f0aa2a;
  --accent-hover: #d89119;
  --danger: #ef4444;
  --sidebar-bg: #1a1a2d;
  --sidebar-hover: #252546;
  --sidebar-active: #303052;
  --sidebar-text: #8b92ad;
  --sidebar-bright: #d7dcf0;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(15,23,42,.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.init-loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 9999;
}
.init-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toasts {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
}
.toast {
  margin-bottom: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.toast.error { background: var(--danger); }

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}
.auth-card {
  width: 100%;
  max-width: 390px;
  padding: 34px 30px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-logo, .sidebar-logo {
  font-size: 30px;
  font-weight: 720;
  letter-spacing: -1px;
}
.auth-logo span, .sidebar-logo span { color: var(--accent); }
.auth-subtitle {
  margin: 4px 0 24px;
  color: var(--muted);
  font-size: 16px;
}

.form-row { margin-bottom: 14px; }
.form-row label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
  text-transform: uppercase;
}
input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-error {
  min-height: 18px;
  margin: 4px 0;
  color: var(--danger);
  font-size: 13px;
}
.auth-switch {
  margin: 14px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 620; }

.btn-primary {
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--accent);
  color: #1f1a10;
  font-weight: 620;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-block { width: 100%; padding: 12px; }

.app {
  height: 100dvh;
  display: flex;
  overflow: hidden;
}
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: #fff;
  overflow: hidden;
}
.sidebar-header {
  padding: 64px 20px 48px;
}
.sidebar-logo {
  font-size: 42px;
  text-align: center;
}
.sidebar-section-title {
  padding: 0 18px 10px;
  color: #747b98;
  font-size: 12px;
  font-weight: 620;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.sidebar-nav {
  display: grid;
  gap: 6px;
  padding: 0 10px;
}
.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 13px 14px;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  font-weight: 520;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  transition: background .15s ease, color .15s ease;
}
.nav-item svg,
.sidebar-footer-link svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  opacity: .82;
}
.nav-item:hover, .nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.sidebar-footer {
  margin-top: auto;
  display: block;
  padding: 0;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-footer-block {
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-footer-link {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  padding: 0 18px;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  font-weight: 500;
}
.sidebar-footer-link:hover {
  background: rgba(255,255,255,.03);
  color: var(--sidebar-bright);
}
.sidebar-account {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #20160a;
  font-weight: 620;
}
.btn-logout {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
  color: var(--sidebar-text);
  display: grid;
  place-items: center;
}
.btn-logout svg {
  width: 18px;
  height: 18px;
}
.btn-logout:hover {
  background: rgba(255,255,255,.06);
  color: var(--sidebar-bright);
}
.user-name {
  overflow: hidden;
  color: var(--sidebar-text);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: 34px 38px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.topbar h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 620;
}
.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
}
.btn-icon {
  display: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
}
.btn-icon span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 4px auto;
  background: var(--text);
}

.toolbar, .stats, .person-first-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}
.toolbar {
  grid-template-columns: minmax(280px, 1fr) 190px;
}
.stats {
  grid-template-columns: repeat(3, minmax(130px, 1fr));
}
.stat, .panel, .doc-card, .person-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(15,23,42,.04), 0 8px 28px rgba(15,23,42,.04);
}
.stat {
  padding: 16px;
}
.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
  text-transform: uppercase;
}
.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  font-weight: 620;
}
.person-first-grid {
  grid-template-columns: 270px minmax(360px, 1fr) 360px;
  align-items: start;
}
.panel {
  padding: 18px;
}
.panel h2 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 620;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 {
  margin: 0;
}
.panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.people-panel, .action-panel {
  position: sticky;
  top: 0;
}
.action-panel {
  display: grid;
  gap: 18px;
}
.person-editor {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.upload-block h2 {
  margin: 0 0 6px;
}
.form-hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}
fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
fieldset:disabled {
  opacity: .58;
}
.documents-list, .people-list {
  display: grid;
  gap: 10px;
}
.doc-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  box-shadow: none;
}
.doc-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.doc-card h3 {
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 620;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-card p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.doc-meta span, .badge {
  border-radius: 999px;
  padding: 3px 8px;
  background: #fff7df;
  color: #8a5d0a;
  font-size: 12px;
  font-weight: 560;
}
.doc-meta .danger { background: #fef2f2; color: var(--danger); }
.badge-fav { background: #fef3c7; color: #b45309; }
.doc-actions {
  display: flex;
  gap: 6px;
}
.doc-actions button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}
.empty-state {
  margin: 0;
  padding: 28px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}
.check-row {
  display: grid;
  gap: 8px;
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 14px;
}
.check-row input { width: auto; }
.person-card {
  display: grid;
  gap: 10px;
  padding: 10px;
  box-shadow: none;
}
.person-card.active {
  border-color: rgba(240,170,42,.72);
  box-shadow: 0 0 0 2px rgba(240,170,42,.14);
}
.person-card-main {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 10px;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}
.person-card-main span {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.person-card-main strong {
  overflow: hidden;
  font-size: 15px;
  font-weight: 610;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.person-card-main small {
  border-radius: 999px;
  padding: 2px 6px;
  background: #fff7df;
  color: #8a5d0a;
  font-size: 11px;
  font-weight: 560;
}
.person-card-main em {
  overflow: hidden;
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.person-card-main b {
  grid-row: 1 / 3;
  grid-column: 2;
  align-self: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
}
.person-card-actions, .form-actions {
  display: flex;
  gap: 8px;
}
.person-card-actions button,
.btn-light,
.btn-danger {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
}
.btn-light:hover,
.person-card-actions button:hover {
  border-color: var(--accent);
  color: var(--text);
}
.btn-danger {
  color: var(--danger);
}
.btn-danger:disabled,
.person-card-actions button:disabled {
  cursor: not-allowed;
  opacity: .45;
}
.sidebar-overlay { display: none; }

@media (max-width: 1180px) {
  .person-first-grid {
    grid-template-columns: 240px minmax(0, 1fr);
  }
  .action-panel {
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
  }
  .people-panel, .action-panel {
    position: static;
  }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .18s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(15,23,42,.45);
  }
  .main {
    padding: calc(var(--safe-top) + 14px) 14px calc(var(--safe-bottom) + 24px);
  }
  .btn-icon { display: block; }
  .toolbar, .stats, .person-first-grid, .action-panel {
    grid-template-columns: 1fr;
  }
  .people-panel, .action-panel {
    position: static;
  }
  .action-panel { order: 3; }
}

@media (max-width: 520px) {
  .topbar h1 { font-size: 21px; }
  .form-pair, .doc-card {
    grid-template-columns: 1fr;
  }
  .doc-actions {
    justify-content: flex-start;
  }
}
