/* ============================================================
   COMPONENTS
   Переиспользуемые UI-блоки. Зависит от tokens.css.
   ============================================================ */

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

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

/* ── Topbar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 var(--s4); gap: var(--s2);
  z-index: 100;
}
.topbar-title {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 12px; color: var(--text-dimmer);
  letter-spacing: 0.07em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center;
}
.topbar-meta {
  font-family: var(--font-ui);
  font-size: 11px; color: var(--text-dimmer);
  min-width: 32px; text-align: right;
}

/* ── Icon button ── */
.btn-icon {
  width: 38px; height: 38px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  transition: background var(--duration) var(--ease-out),
              color     var(--duration) var(--ease-out),
              border-color var(--duration) var(--ease-out);
}
.btn-icon:hover, .btn-icon.active {
  background: var(--bg3);
  color: var(--accent);
  border-color: var(--accent-glow);
}

/* ── Button ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 12px; letter-spacing: 0.06em;
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 700;
}
.btn-primary:hover { background: var(--accent-light); border-color: var(--accent-light); color: white; }

.btn-full { width: 100%; }

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: var(--header-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  transform: translateX(calc(-1 * var(--sidebar-w)));
  transition: transform var(--duration) var(--ease-out);
  z-index: 90;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar.open { transform: translateX(0); }

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-tab {
  flex: 1; padding: 11px 6px;
  background: transparent; border: none;
  color: var(--text-dimmer);
  font-family: var(--font-ui); font-size: 10px; letter-spacing: 0.08em;
  cursor: pointer; transition: all var(--duration);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.sidebar-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sidebar-panel { display: none; flex: 1; overflow-y: auto; padding: var(--s2) 0; }
.sidebar-panel.active { display: block; }

/* Sidebar list items */
.sidebar-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--duration);
}
.sidebar-item:hover { background: var(--bg3); }
.sidebar-item:last-child { border-bottom: none; }

/* ── Overlay ── */
.overlay {
  display: none; position: fixed; inset: 0;
  z-index: 89;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
}
.overlay.visible { display: block; }

/* ── Settings panel — desktop right / mobile bottom sheet ── */
.settings-panel {
  position: fixed;
  top: var(--header-h); right: 0;
  width: 270px; bottom: 0;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  transform: translateX(270px);
  transition: transform var(--duration) var(--ease-out);
  z-index: 95;
  padding: var(--s5) var(--s4);
  overflow-y: auto;
}
.settings-panel.open { transform: translateX(0); }

.settings-section {
  font-family: var(--font-ui); font-size: 10px;
  color: var(--text-dimmer); letter-spacing: 0.14em;
  margin-bottom: var(--s3); margin-top: var(--s2);
}
.settings-row { margin-bottom: var(--s5); }
.settings-label {
  font-size: 13px; color: var(--text-dim);
  margin-bottom: var(--s2); display: block;
}

@media (max-width: 700px) {
  .settings-panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%; max-height: 82vh;
    border-left: none; border-top: 1px solid var(--border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    transform: translateY(100%);
    padding: 0 var(--s5) calc(var(--s6) + env(safe-area-inset-bottom));
  }
  .settings-panel.open { transform: translateY(0); }
  .settings-panel::before {
    content: ''; display: block;
    width: 36px; height: 4px;
    background: var(--text-dimmer); border-radius: 2px;
    margin: var(--s3) auto var(--s4); opacity: 0.35;
  }
}

/* ── Main content area ── */
.main-area {
  position: fixed;
  top: calc(var(--header-h) + 2px);
  left: 0; right: 0; bottom: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.main-wrap {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s7) var(--s5) 120px;
}
@media (max-width: 700px) {
  .main-wrap { padding: var(--s6) var(--s4) 100px; }
}

/* ── Progress bar (top) ── */
.progress-bar-track {
  position: fixed; top: var(--header-h); left: 0; right: 0;
  height: 2px; background: var(--bg3); z-index: 99;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-glow), var(--accent));
  width: 0%; transition: width 0.3s var(--ease-out);
}

/* ── Card ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.card-section {
  padding: var(--s5);
  border-bottom: 1px solid var(--border);
}
.card-section:last-child { border-bottom: none; }

/* ── Input ── */
.input {
  width: 100%; height: 38px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body); font-size: 14px;
  padding: 0 var(--s3);
  outline: none;
  transition: border-color var(--duration);
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-dimmer); }

.textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body); font-size: 14px;
  padding: var(--s3);
  outline: none; resize: vertical;
  transition: border-color var(--duration);
  line-height: 1.6;
}
.textarea:focus { border-color: var(--accent); }

/* ── Checkbox row ── */
.check-row {
  display: flex; align-items: center; gap: var(--s3);
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--s3) var(--s4);
  cursor: pointer;
  user-select: none;
  transition: border-color var(--duration), background var(--duration);
}
.check-row:hover { background: var(--bg3); }
.check-row.done { background: rgba(42,122,58,0.08); border-color: rgba(42,122,58,0.4); }
.checkbox {
  width: 22px; height: 22px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border2);
  background: transparent; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--duration);
}
.check-row.done .checkbox { background: var(--success); border-color: var(--success); }
.checkbox-mark { opacity: 0; font-size: 13px; color: white; font-weight: 700; }
.check-row.done .checkbox-mark { opacity: 1; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: var(--s5); left: 50%;
  transform: translateX(-50%);
  background: var(--text); color: var(--bg2);
  border-radius: 20px;
  padding: 7px 18px;
  font-family: var(--font-ui); font-size: 12px;
  white-space: nowrap; z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.toast.visible { opacity: 1; }

/* ── Alert / Error ── */
.alert {
  padding: var(--s3) var(--s4);
  border-radius: var(--radius-md);
  font-size: 13px;
  display: none;
}
.alert.visible { display: block; }
.alert-error {
  background: rgba(192,48,48,0.08);
  border: 1px solid rgba(192,48,48,0.25);
  color: var(--danger);
}
.alert-success {
  background: rgba(42,122,58,0.08);
  border: 1px solid rgba(42,122,58,0.25);
  color: var(--success);
}

/* ── Theme buttons ── */
.theme-btns { display: flex; gap: var(--s2); }
.theme-btn {
  flex: 1; padding: 7px 4px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  font-family: var(--font-ui); font-size: 10px; letter-spacing: 0.06em;
  text-align: center; transition: all var(--duration);
}
.theme-btn[data-theme="light"] { background: #f0ede8; color: #c05a1a; border-color: #d4c8b0; }
.theme-btn[data-theme="dark"]  { background: #1a1612; color: #c9a84c; border-color: #3a3228; }
.theme-btn[data-theme="sepia"] { background: #f2e8d0; color: #8a5010; border-color: #c8b890; }
.theme-btn.active { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Font size control ── */
.font-size-ctrl { display: flex; align-items: center; gap: var(--s3); }
.font-size-btn {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border2);
  background: transparent; color: var(--text-dim);
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--duration);
}
.font-size-btn:hover { background: var(--bg3); color: var(--accent); }
.font-size-val {
  flex: 1; text-align: center;
  font-family: var(--font-ui); font-size: 13px; color: var(--text-dim);
}

/* ── Range slider ── */
.slider { width: 100%; accent-color: var(--accent); cursor: pointer; }

/* ── Empty state ── */
.empty-state {
  padding: var(--s7) var(--s5);
  text-align: center;
  color: var(--text-dimmer);
  font-size: 14px; font-style: italic;
  line-height: 1.7;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dimmer); }
