/* Cloude Uchat — monotone, low-contrast panel style.
   Self-hosted Inter (variable) so nothing leaves the server on page load. */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("fonts/inter-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F, U+2190-2193, U+2212, U+2215;
}

:root {
  --font: "Inter", ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;

  --bg: #fbfbfc;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #ececee;
  --border-strong: #dcdce0;
  --text: #26262a;
  --text-dim: #77777e;
  --text-faint: #a9a9b0;
  --accent: #2e2e33;
  --accent-hover: #141417;
  --accent-fg: #ffffff;
  --accent-tint: #f1f1f3;
  --danger: #a8362d;
  --danger-tint: #f9efee;
  --success: #4a7d63;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);

  --ctl-h: 30px;      /* shared control height — keeps the toolbar visually level */
  --sidebar-w: 228px;
  --topbar-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416;
    --surface: #1a1a1c;
    --surface-2: #222225;
    --border: #29292d;
    --border-strong: #3a3a3f;
    --text: #e4e4e6;
    --text-dim: #97979e;
    --text-faint: #67676e;
    --accent: #e4e4e6;
    --accent-hover: #ffffff;
    --accent-fg: #18181a;
    --accent-tint: #26262a;
    --danger: #d08079;
    --danger-tint: #2a1d1c;
    --success: #85ab97;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  --bg: #141416;
  --surface: #1a1a1c;
  --surface-2: #222225;
  --border: #29292d;
  --border-strong: #3a3a3f;
  --text: #e4e4e6;
  --text-dim: #97979e;
  --text-faint: #67676e;
  --accent: #e4e4e6;
  --accent-hover: #ffffff;
  --accent-fg: #18181a;
  --accent-tint: #26262a;
  --danger: #d08079;
  --danger-tint: #2a1d1c;
  --success: #85ab97;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font-family: inherit; letter-spacing: inherit; }
a { color: var(--text); text-underline-offset: 2px; }
.hidden, [hidden] { display: none !important; }

svg { stroke-width: 1.5; }

/* ---------- form controls ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 450;
  color: var(--text-dim);
}

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0 10px;
  height: var(--ctl-h);
  font-size: 13px;
  font-weight: 400;
  width: 100%;
  transition: border-color .12s ease, background .12s ease;
}
textarea { height: auto; padding: 8px 10px; line-height: 1.5; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:hover, textarea:hover, select:hover { border-color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--text-dim);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

input[type="file"] { padding: 5px 8px; height: auto; font-size: 12px; color: var(--text-dim); }

/* ---------- buttons ---------- */
button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--ctl-h);
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 450;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease, opacity .12s ease;
}
button:hover { background: var(--surface-2); }
button:active { transform: translateY(.5px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:disabled:hover { background: var(--surface); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-tint); border-color: var(--text-dim); }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

button.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }

button.quiet { background: transparent; border-color: transparent; color: var(--text-dim); padding: 0 8px; }
button.quiet:hover { background: var(--surface-2); color: var(--text); }

button.danger-text { background: transparent; border-color: transparent; color: var(--text-dim); padding: 0 8px; }
button.danger-text:hover { background: var(--danger-tint); color: var(--danger); }

button.danger-solid {
  background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 500;
}
button.danger-solid:hover { background: var(--danger); border-color: var(--danger); filter: brightness(.92); }

button.icon-btn { width: var(--ctl-h); height: var(--ctl-h); padding: 0; }
button.block { width: 100%; }

/* ---------- login ---------- */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 332px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card .brand-mark { display: flex; align-items: center; gap: 9px; }
.login-card .brand-mark .logo-dot {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--accent); flex-shrink: 0;
}
.login-card h1 { margin: 0; font-size: 15px; font-weight: 550; letter-spacing: -0.015em; }
.login-card .subtitle { margin: -8px 0 4px; color: var(--text-faint); font-size: 12px; }
.login-card button[type="submit"] { margin-top: 4px; height: 34px; }

.error-text { color: var(--danger); font-size: 12px; margin: 0; }
.login-card .error-text { background: var(--danger-tint); padding: 7px 10px; border-radius: var(--radius-sm); }
.login-footnote { color: var(--text-faint); font-size: 11px; text-align: center; margin: 2px 0 0; line-height: 1.45; }

/* ---------- app shell ---------- */
#app-view { height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
}

.topbar .brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 550; letter-spacing: -0.015em;
  flex-shrink: 0; margin-right: 6px;
}
.topbar .brand .logo-dot { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); }

.search-wrap { flex: 1; max-width: 400px; position: relative; }
.search-wrap input { padding-left: 31px; background: var(--surface-2); border-color: transparent; }
.search-wrap input:hover { border-color: var(--border-strong); }
.search-wrap input:focus { background: var(--surface); }
.search-wrap svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--text-faint); pointer-events: none;
}

.topbar-spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

.lang-select {
  width: auto; padding: 0 6px; height: 26px; font-size: 11.5px; font-weight: 450;
  color: var(--text-dim); background: transparent; border-color: transparent;
}
.lang-select:hover { background: var(--surface-2); border-color: transparent; }

.avatar {
  width: 25px; height: 25px; border-radius: 50%; margin: 0 4px 0 6px;
  background: var(--surface-2); color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  font-weight: 500; font-size: 10.5px; letter-spacing: 0;
  border: 1px solid var(--border-strong);
}

.app-body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.nav-group-label {
  font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-faint); font-weight: 500; padding: 0 8px; margin-bottom: 4px;
  display: flex; align-items: center; justify-content: space-between;
}

.sidebar-grow { flex: 1; }

.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 0 8px; height: 30px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-dim); font-weight: 450; font-size: 12.5px;
  white-space: nowrap; overflow: hidden;
  transition: background .1s ease, color .1s ease;
}
.nav-item .nav-icon {
  flex-shrink: 0; width: 15px; height: 15px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 13px;
}
.nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item:hover .nav-icon { color: var(--text-dim); }
.nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 500; }
.nav-item.active .nav-icon { color: var(--text); }

.nav-item .cat-delete {
  opacity: 0; flex-shrink: 0; width: 20px; height: 20px; padding: 0;
  color: var(--text-faint); background: none; border: none; font-size: 12px;
}
.nav-item:hover .cat-delete { opacity: 1; }
.nav-item .cat-delete:hover { color: var(--danger); background: transparent; }

.sidebar .nav-group-label button {
  width: 20px; height: 20px; padding: 0; border: none; background: transparent; color: var(--text-faint);
}
.sidebar .nav-group-label button:hover { background: var(--surface-2); color: var(--text); }

/* ---------- content ---------- */
.content { flex: 1; overflow-y: auto; padding: 20px 24px 56px; min-width: 0; }

.content-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.content-head h2 { margin: 0; font-size: 16px; font-weight: 550; letter-spacing: -0.018em; }
.content-head-actions { display: flex; align-items: center; gap: 6px; }

.view-toggle {
  display: flex; gap: 1px; padding: 1px;
  background: var(--surface-2); border-radius: var(--radius-sm);
}
.view-toggle button {
  border: none; border-radius: 5px; height: 26px; width: 28px; padding: 0;
  background: transparent; color: var(--text-faint);
}
.view-toggle button:hover { background: transparent; color: var(--text-dim); }
.view-toggle button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.05); }

.empty-state {
  color: var(--text-faint); text-align: center; padding: 72px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.empty-state svg { width: 26px; height: 26px; color: var(--text-faint); stroke-width: 1.25; }
.empty-state p { margin: 0; font-size: 12.5px; }

/* ---------- block cards ---------- */
.block-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(226px, 1fr)); gap: 8px; }
.block-grid.list-mode { grid-template-columns: 1fr; gap: 0; }

.block-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color .12s ease;
}
.block-card:hover { border-color: var(--border-strong); }

.list-mode .block-card {
  flex-direction: row; align-items: center; padding: 0 10px; height: 46px; gap: 10px;
  border-radius: 0; border-width: 0 0 1px 0;
}
.list-mode .block-card:first-child { border-radius: var(--radius) var(--radius) 0 0; border-top-width: 1px; }
.list-mode .block-card:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.list-mode .block-card:hover { background: var(--surface-2); }

.block-card-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.list-mode .block-card-top { flex: 1; }

/* Types are told apart by icon glyph only — no per-type hues, so the grid stays calm. */
.type-badge {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  background: var(--surface-2); color: var(--text-dim);
}
.type-badge svg { width: 14px; height: 14px; }
.list-mode .type-badge { width: 22px; height: 22px; background: transparent; }

.block-card-title {
  font-weight: 450; font-size: 12.5px; color: var(--text);
  word-break: break-word; min-width: 0; line-height: 1.35;
}
.block-card-meta { font-size: 10.5px; color: var(--text-faint); font-weight: 400; margin-top: 1px; }

.block-actions {
  display: flex; align-items: center; gap: 2px;
  margin-top: auto; justify-content: space-between;
}
.list-mode .block-actions { margin-top: 0; flex-shrink: 0; }

.block-actions .card-action {
  height: 26px; padding: 0 10px; font-size: 11.5px;
  border-color: transparent; background: var(--surface-2); color: var(--text-dim);
}
.block-actions .card-action:hover { background: var(--border); color: var(--text); }

/* Destructive action stays an unlabelled icon and only surfaces on hover, so a grid of
   cards doesn't read as a wall of "Delete" buttons. Always shown on touch (no hover). */
.block-actions .card-delete {
  width: 26px; height: 26px; padding: 0; flex-shrink: 0;
  border-color: transparent; background: transparent; color: var(--text-faint);
  opacity: 0; transition: opacity .1s ease, color .12s ease, background .12s ease;
}
.block-card:hover .card-delete { opacity: 1; }
.block-actions .card-delete:hover { background: var(--danger-tint); color: var(--danger); }
.block-actions .card-delete:focus-visible { opacity: 1; }

@media (hover: none) {
  .block-actions .card-delete { opacity: 1; }
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .35);
  display: flex; align-items: center; justify-content: center; z-index: 60;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }

.panel {
  width: 380px; max-width: 100%; max-height: calc(100vh - 32px);
  overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.panel.wide { width: 460px; }
.panel h3 { margin: 0 0 2px; font-size: 13.5px; font-weight: 550; letter-spacing: -0.012em; }
.panel-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 4px; }

.type-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.type-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
  height: 74px; padding: 8px 4px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface);
  font-size: 11px; font-weight: 450; color: var(--text-dim); line-height: 1.2;
}
.type-tile:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
.type-tile:disabled { opacity: .35; }
.type-tile .type-badge { width: 26px; height: 26px; }
.type-tile .type-badge svg { width: 13px; height: 13px; }

.kv-row { display: flex; align-items: center; gap: 8px; }
.kv-row label { width: 60px; flex-shrink: 0; font-size: 11.5px; color: var(--text-faint); font-weight: 450; }
.kv-row .kv-value {
  flex: 1; font-family: var(--mono); font-size: 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 9px; word-break: break-all;
}
.kv-row button { height: 28px; font-size: 11.5px; padding: 0 9px; }

.doc-text {
  white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px; max-height: 48vh; overflow-y: auto;
  font-size: 12.5px; line-height: 1.55;
}
.confirm-text { font-size: 12.5px; color: var(--text-dim); margin: 0; line-height: 1.5; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-fg);
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 450; z-index: 100; box-shadow: var(--shadow);
}
#toast[hidden] { display: none; }

/* ---------- loading ---------- */
.skeleton {
  background: var(--surface-2); border-radius: var(--radius);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .55 } }
.skeleton-card { height: 78px; }

/* ---------- mobile ---------- */
.bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .sidebar.mobile-open {
    display: flex; position: fixed; inset: var(--topbar-h) 0 52px 0; z-index: 40; width: auto;
    padding: 12px;
  }
  .content { padding: 14px 14px 72px; }
  .block-grid { grid-template-columns: 1fr; }
  .search-wrap { max-width: none; }
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar .brand-text, .lang-select { display: none; }
  .list-mode .block-actions { opacity: 1; }
  .type-grid { grid-template-columns: repeat(3, 1fr); }
  .type-tile { height: 80px; }

  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 52px;
    background: var(--surface); border-top: 1px solid var(--border); z-index: 45;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav button {
    flex: 1; border: none; border-radius: 0; background: transparent; height: 52px;
    flex-direction: column; gap: 3px;
    font-size: 9.5px; font-weight: 450; color: var(--text-faint); padding: 0;
  }
  .bottom-nav button:hover { background: transparent; }
  .bottom-nav button.active { color: var(--text); }
  .bottom-nav svg { width: 17px; height: 17px; }
}

@media (min-width: 861px) {
  .mobile-menu-btn { display: none; }
}
