/* ============================================================
   COMPONENTS — Material Design 3
   Переиспользуемые 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;
}

#hs-app-root {
  min-height: 100%;
}

/* ── Topbar (MD3 Top App Bar) ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--md-surface);
  display: flex; align-items: center;
  padding: 0 var(--s3); gap: var(--s2);
  z-index: 100;
}
.topbar-title {
  flex: 1;
  font-family: var(--font-ui);
  font-size: var(--text-title); font-weight: 500;
  color: var(--md-on-surface);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center;
}
.topbar-meta {
  font-family: var(--font-ui);
  font-size: var(--text-label);
  color: var(--md-on-surface-variant);
  min-width: 32px; text-align: right;
}
.topbar-home {
  position: sticky;
  justify-content: space-between;
  border-bottom: 1px solid var(--md-outline-variant);
  box-shadow: var(--elevation-0);
  padding: 0 var(--s5);
}
.topbar-home .topbar-title {
  flex: 0 0 auto;
  text-align: left;
  letter-spacing: 0.1em;
  font-size: var(--text-label);
  font-weight: 700;
  color: var(--md-primary);
}
.topbar-home .topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s2);
  flex: 1;
}

/* ── Icon Button (MD3 Standard) ── */
.btn-icon {
  width: 40px; height: 40px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--md-on-surface-variant);
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: background var(--duration) var(--ease-standard),
              color var(--duration) var(--ease-standard);
}
.btn-icon:hover {
  background: color-mix(in srgb, var(--md-on-surface-variant) 8%, transparent);
}
.btn-icon.active {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}

/* ── Button (MD3 Outlined) ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 40px; padding: 0 var(--s5);
  border-radius: var(--radius-full);
  border: 1px solid var(--md-outline);
  background: transparent;
  color: var(--md-primary);
  font-family: var(--font-ui);
  font-size: var(--text-body); font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all var(--duration) var(--ease-standard);
  white-space: nowrap;
}
.btn:hover {
  background: color-mix(in srgb, var(--md-primary) 8%, transparent);
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.38; cursor: not-allowed; pointer-events: none; }
.btn-compact {
  height: 32px;
  padding: 0 var(--s4);
  font-size: var(--text-label);
}

/* Filled */
.btn-primary {
  background: var(--md-primary);
  color: var(--md-on-primary);
  border-color: transparent;
}
.btn-primary:hover {
  background: color-mix(in srgb, var(--md-on-primary) 8%, var(--md-primary));
  box-shadow: var(--elevation-1);
  color: var(--md-on-primary);
}

/* Tonal */
.btn-tonal {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border-color: transparent;
}
.btn-tonal:hover {
  background: color-mix(in srgb, var(--md-on-secondary-container) 8%, var(--md-secondary-container));
  box-shadow: var(--elevation-1);
}

/* Full width */
.btn-full { width: 100%; }

/* ── Sidebar (MD3 Navigation Drawer) ── */
.sidebar {
  position: fixed;
  top: var(--header-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--md-surface-container-low);
  transform: translateX(calc(-1 * var(--sidebar-w)));
  transition: transform var(--duration-medium) var(--ease-emphasized);
  z-index: 90;
  display: flex; flex-direction: column;
  overflow: hidden;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}
.sidebar.open { transform: translateX(0); }

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--md-outline-variant);
  flex-shrink: 0;
}
.sidebar-tab {
  flex: 1; padding: var(--s3) var(--s2);
  background: transparent; border: none;
  color: var(--md-on-surface-variant);
  font-family: var(--font-ui); font-size: var(--text-label); font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer; transition: all var(--duration);
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.sidebar-tab:hover {
  background: color-mix(in srgb, var(--md-primary) 8%, transparent);
}
.sidebar-tab.active {
  color: var(--md-primary);
  border-bottom-color: var(--md-primary);
}

#sidebar-panels { flex: 1; min-height: 0; overflow: hidden; }
.sidebar-panel { display: none; height: 100%; overflow-y: auto; padding: var(--s2) 0; }
.sidebar-panel.active { display: block; }

/* MD3 Navigation Drawer Items */
.sidebar-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  margin: 2px var(--s3);
  border-radius: var(--radius-full);
  cursor: pointer;
  color: var(--md-on-surface-variant);
  transition: background var(--duration);
}
.sidebar-item:hover {
  background: color-mix(in srgb, var(--md-on-surface) 8%, transparent);
}
.sidebar-item.active {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  font-weight: 500;
}

/* ── Overlay (MD3 Scrim) ── */
.overlay {
  display: none; position: fixed; inset: 0;
  z-index: 89;
  background: var(--md-scrim);
}
.overlay.visible { display: block; }

.screen-shell {
  min-height: calc(100vh - var(--header-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s5);
}

.screen-card {
  width: min(100%, 480px);
  padding: var(--s5);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  text-align: center;
}

.screen-actions {
  display: flex;
  justify-content: center;
  gap: var(--s2);
  margin-top: var(--s2);
}

/* ── Settings Panel ── */
.settings-panel {
  position: fixed;
  top: var(--header-h); right: 0;
  width: 300px; bottom: 0;
  background: var(--md-surface-container-low);
  box-shadow: var(--elevation-3);
  transform: translateX(300px);
  transition: transform var(--duration-medium) var(--ease-emphasized);
  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: var(--text-label);
  color: var(--md-primary); font-weight: 500;
  letter-spacing: 0.04em;
  margin-bottom: var(--s3); margin-top: var(--s5);
}
.settings-section:first-child { margin-top: 0; }
.settings-row { margin-bottom: var(--s5); }
.settings-label {
  font-size: var(--text-body);
  color: var(--md-on-surface-variant);
  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;
    box-shadow: var(--elevation-5);
    border-left: none;
    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: 32px; height: 4px;
    background: var(--md-on-surface-variant);
    border-radius: var(--radius-full);
    margin: var(--s3) auto var(--s4); opacity: 0.4;
  }
}

/* ── Main Content ── */
.main-area {
  position: fixed;
  top: var(--header-h);
  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 ── */
.progress-bar-track {
  position: fixed; top: var(--header-h); left: 0; right: 0;
  height: 3px; background: var(--md-surface-container-highest); z-index: 99;
}
.progress-bar-fill {
  height: 100%;
  background: var(--md-primary);
  width: 0%; transition: width 0.3s var(--ease-standard);
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

/* ── Card (MD3 Elevated) ── */
.card {
  background: var(--md-surface-container-low);
  border-radius: var(--radius-md);
  box-shadow: var(--elevation-1);
  overflow: hidden;
}
.card-outlined {
  background: var(--md-surface);
  border: 1px solid var(--md-outline-variant);
  box-shadow: none;
}
.card-filled {
  background: var(--md-surface-container-highest);
  box-shadow: none;
}
.card-section {
  padding: var(--s5);
  border-bottom: 1px solid var(--md-outline-variant);
}
.card-section:last-child { border-bottom: none; }

/* ── Typography helpers ── */
.type-headline {
  font-family: var(--font-ui);
  font-size: var(--text-headline);
  line-height: 1.25;
  font-weight: 600;
  color: var(--md-on-surface);
}
.type-title {
  font-family: var(--font-ui);
  font-size: var(--text-title);
  line-height: 1.4;
  font-weight: 600;
  color: var(--md-on-surface);
}
.type-subhead {
  font-family: var(--font-ui);
  font-size: var(--text-label);
  line-height: 1.35;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--md-on-surface-variant);
  text-transform: uppercase;
}

/* ── Input (MD3 Outlined) ── */
.input {
  width: 100%; height: 44px;
  background: transparent;
  border: 1px solid var(--md-outline);
  border-radius: var(--radius-xs);
  color: var(--md-on-surface);
  font-family: var(--font-body); font-size: var(--text-body-lg);
  padding: 0 var(--s4);
  outline: none;
  transition: border-color var(--duration);
}
.input:hover { border-color: var(--md-on-surface); }
.input:focus { border-color: var(--md-primary); border-width: 2px; padding: 0 calc(var(--s4) - 1px); }
.input::placeholder { color: var(--md-on-surface-variant); }

.textarea {
  width: 100%;
  background: transparent;
  border: 1px solid var(--md-outline);
  border-radius: var(--radius-xs);
  color: var(--md-on-surface);
  font-family: var(--font-body); font-size: var(--text-body-lg);
  padding: var(--s3) var(--s4);
  outline: none; resize: vertical;
  transition: border-color var(--duration);
  line-height: 1.6;
}
.textarea:hover { border-color: var(--md-on-surface); }
.textarea:focus { border-color: var(--md-primary); border-width: 2px; padding: calc(var(--s3) - 1px) calc(var(--s4) - 1px); }

/* ── Checkbox Row ── */
.check-row {
  display: flex; align-items: center; gap: var(--s3);
  background: var(--md-surface-container-low);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--radius-md);
  padding: var(--s3) var(--s4);
  cursor: pointer;
  user-select: none;
  transition: background var(--duration);
}
.check-row:hover { background: var(--md-surface-container); }
.check-row.done {
  background: var(--md-tertiary-container);
  border-color: color-mix(in srgb, var(--md-tertiary) 40%, transparent);
}
.checkbox {
  width: 20px; height: 20px;
  border-radius: var(--radius-xs);
  border: 2px solid var(--md-outline);
  background: transparent; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--duration);
}
.check-row.done .checkbox {
  background: var(--md-tertiary);
  border-color: var(--md-tertiary);
}
.checkbox-mark { opacity: 0; font-size: 13px; color: var(--md-on-tertiary); font-weight: 700; }
.check-row.done .checkbox-mark { opacity: 1; }

/* ── Toast (MD3 Snackbar) ── */
.toast {
  position: fixed; bottom: var(--s6); left: 50%;
  transform: translateX(-50%) translateY(var(--s4));
  background: var(--md-inverse-surface);
  color: var(--md-inverse-on-surface);
  border-radius: var(--radius-sm);
  padding: var(--s3) var(--s4);
  font-family: var(--font-body); font-size: var(--text-body);
  white-space: nowrap; z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity var(--duration-short),
              transform var(--duration-short) var(--ease-decelerate);
  box-shadow: var(--elevation-3);
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Alerts (MD3 Banner) ── */
.alert {
  padding: var(--s3) var(--s4);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  display: none;
}
.alert.visible { display: block; }
.alert-error {
  background: var(--md-error-container);
  color: var(--md-on-error-container);
}
.alert-success {
  background: var(--md-tertiary-container);
  color: var(--md-on-tertiary-container);
}

/* ── Theme Buttons ── */
.theme-btns { display: flex; gap: var(--s2); }
.theme-btn {
  flex: 1; padding: var(--s2) var(--s1);
  border-radius: var(--radius-sm);
  border: 1px solid var(--md-outline-variant);
  cursor: pointer;
  font-family: var(--font-ui); font-size: var(--text-label); font-weight: 500;
  text-align: center; transition: all var(--duration);
  background: transparent;
}
.theme-btn[data-theme="light"]  { background: #FFF8F6; color: #B5380A; }
.theme-btn[data-theme="dark"]   { background: #1A1110; color: #FFB4A0; }
.theme-btn[data-theme="violet"] { background: #FFFBFE; color: #6750A4; }
.theme-btn.active {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
  border-color: var(--md-primary);
}

/* ── Font Size Control ── */
.font-size-ctrl { display: flex; align-items: center; gap: var(--s3); }
.font-size-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--md-surface-container-high);
  color: var(--md-on-surface-variant);
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--duration);
}
.font-size-btn:hover {
  background: var(--md-surface-container-highest);
  color: var(--md-primary);
}
.font-size-val {
  flex: 1; text-align: center;
  font-family: var(--font-ui); font-size: var(--text-body);
  color: var(--md-on-surface-variant);
}

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

/* ── Chip (MD3) ── */
.chip {
  display: inline-flex; align-items: center; gap: var(--s1);
  height: 32px; padding: 0 var(--s3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--md-outline);
  background: transparent;
  color: var(--md-on-surface-variant);
  font-family: var(--font-ui); font-size: var(--text-label); font-weight: 500;
  cursor: pointer; transition: all var(--duration);
}
.chip:hover {
  background: color-mix(in srgb, var(--md-on-surface-variant) 8%, transparent);
}
.chip.active {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border-color: transparent;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--md-outline-variant);
  border: none;
  margin: var(--s2) 0;
}

/* ── FAB (MD3 Floating Action Button) ── */
.fab {
  width: 56px; height: 56px;
  border-radius: var(--radius-lg);
  border: none;
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  font-size: 24px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--elevation-3);
  transition: all var(--duration-medium) var(--ease-standard);
  position: fixed;
}
.fab:hover {
  box-shadow: var(--elevation-4);
  background: color-mix(in srgb, var(--md-on-primary-container) 8%, var(--md-primary-container));
}
.fab-sm {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  font-size: 18px;
}

/* ── Empty State ── */
.empty-state {
  padding: var(--s7) var(--s5);
  text-align: center;
  color: var(--md-on-surface-variant);
  font-size: var(--text-body-lg);
  line-height: 1.7;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--md-outline-variant); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--md-outline); }
