/* «Блоки»: calm, one accent colour, light and dark follow the system. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eaedf1;
  --text: #15171c;
  --text-2: #5b6170;
  --border: #e1e4ea;
  --accent: #3459d1;
  --accent-hover: #2a4bb6;
  --accent-text: #ffffff;
  --danger: #c93434;
  --warn-bg: #fff3dc;
  --warn-text: #7f4d00;
  --focus: rgba(52, 89, 209, 0.35);
  --shadow: 0 1px 2px rgba(15, 20, 30, 0.05), 0 2px 10px rgba(15, 20, 30, 0.05);
  --backdrop: rgba(10, 12, 16, 0.35);
  --radius: 16px;
  --gutter: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #252a33;
    --text: #eceef3;
    --text-2: #a2a8b5;
    --border: #2b3039;
    --accent: #7d97ff;
    --accent-hover: #95abff;
    --accent-text: #0d1130;
    --danger: #ff6b6b;
    --warn-bg: #3a2c12;
    --warn-text: #ffcf87;
    --focus: rgba(125, 151, 255, 0.45);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    --backdrop: rgba(0, 0, 0, 0.55);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* On iPhone this makes the base size follow the system text size setting. */
@supports (font: -apple-system-body) {
  html { font: -apple-system-body; }
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, p { margin: 0; }
button, input { font: inherit; color: inherit; }
img { display: block; }
.muted { color: var(--text-2); }
.ic { flex: none; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
}

.noscript { padding: 24px; text-align: center; }

/* ---------- Buttons and inputs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn-accent { background: var(--accent); color: var(--accent-text); }
.icon-btn-accent:hover { background: var(--accent-hover); }

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-2);
}
.input {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  /* 16px or more stops iPhone from zooming in on focus. */
  font-size: max(16px, 1rem);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.code-input { letter-spacing: 0.25em; font-variant-numeric: tabular-nums; }
.hint { margin-top: 6px; font-size: 0.8125rem; color: var(--text-2); }

/* ---------- Full-screen notices ---------- */

.center {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: calc(var(--sat) + 24px) calc(var(--sar) + 24px) calc(var(--sab) + 24px) calc(var(--sal) + 24px);
  text-align: center;
}
.notice { max-width: 360px; display: grid; gap: 12px; justify-items: center; }
.notice h1 { font-size: 1.5rem; }
.notice p { margin-bottom: 8px; }
.notice-icon { color: var(--text-2); }

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */

.login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: calc(var(--sat) + 24px) calc(var(--sar) + 16px) calc(var(--sab) + 24px) calc(var(--sal) + 16px);
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 24px 24px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { width: 72px; height: 72px; margin: 0 auto; }
.login-card h1 { margin: 16px 0 4px; font-size: 1.6rem; letter-spacing: -0.01em; }
.login-form { display: grid; gap: 16px; margin-top: 24px; text-align: left; }
.form-error { color: var(--danger); font-size: 0.9375rem; }
.form-error:empty { display: none; }

/* ---------- Main screen (phone: one column) ---------- */

.pane-list { display: flex; flex-direction: column; min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(var(--sat) + 6px) calc(var(--sar) + var(--gutter)) 10px calc(var(--sal) + var(--gutter));
  background: var(--bg);
}
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .topbar {
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    backdrop-filter: saturate(180%) blur(16px);
  }
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; }
.title { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }
.topbar-actions { display: flex; gap: 6px; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  margin-top: 6px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-2);
  cursor: text;
}
.search:focus-within { box-shadow: 0 0 0 3px var(--focus); }
.search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: max(16px, 1rem);
}
.search-input::placeholder { color: var(--text-2); }

.list { flex: 1; padding: 8px calc(var(--sar) + var(--gutter)) 16px calc(var(--sal) + var(--gutter)); }

.empty { max-width: 360px; margin: 0 auto; padding: 48px 8px 24px; text-align: center; }
.empty-art { width: 88px; height: 88px; margin: 0 auto; }
.empty h2 { margin: 20px 0 8px; font-size: 1.3rem; }
.empty p { margin-bottom: 24px; }

.pane-footer { padding: 8px calc(var(--sar) + var(--gutter)) calc(var(--sab) + 16px) calc(var(--sal) + var(--gutter)); }
.storage {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.875rem;
}
.storage-head { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.storage-head strong { color: var(--text); font-size: 0.9375rem; font-weight: 600; }
.meter { height: 6px; margin: 10px 0 8px; overflow: hidden; border-radius: 3px; background: var(--surface-2); }
.meter-fill { width: 0; height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.4s; }
.storage-warn { margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); }

.pane-detail { display: none; }

/* ---------- Computer: two panes ---------- */

@media (min-width: 900px) {
  .layout { display: flex; height: 100dvh; overflow: hidden; }
  .pane-list {
    flex: 0 0 380px;
    width: 380px;
    height: 100dvh;
    min-height: 0;
    border-right: 1px solid var(--border);
  }
  .list { overflow-y: auto; overscroll-behavior: contain; }
  .title { font-size: 1.6rem; }
  .pane-detail {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    background: var(--surface);
  }
  .placeholder { padding: 24px; color: var(--text-2); text-align: center; }
}
@media (min-width: 1400px) {
  .pane-list { flex-basis: 440px; width: 440px; }
}

/* ---------- Menu (bottom sheet on phone, centred box on computer) ---------- */

dialog.sheet {
  width: min(420px, calc(100vw - 24px));
  padding: 6px 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
dialog.sheet::backdrop { background: var(--backdrop); }
@media (max-width: 899px) {
  dialog.sheet { margin: auto auto calc(var(--sab) + 12px); }
}
.menu-info { padding: 12px 18px 14px; border-bottom: 1px solid var(--border); color: var(--text-2); font-size: 0.875rem; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sab) + 24px);
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9375rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition: none !important; }
}
