:root {
  --bg: rgb(13, 11, 16);
  --surface: #131017;
  --surface-2: #1a1521;
  --accent: rgb(244, 108, 171);
  --accent-tint: rgba(244, 108, 171, 0.08);
  --border: rgba(255, 255, 255, 0.07);
  --text: #e8e4ee;
  --text-dim: #6d6678;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  font-family: var(--mono);
  color: var(--text);
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1100px 500px at 70% -10%, rgba(244, 108, 171, 0.06), transparent 60%),
    var(--bg);
}

/* --- экраны --- */

.hidden { display: none !important; }

.screen { display: none; width: 100%; }
body[data-screen="loading"] #loading-screen,
body[data-screen="activation"] #activation-screen,
body[data-screen="recovery"] #recovery-screen,
body[data-screen="lock"] #lock-screen,
body[data-screen="pin"] #pin-screen,
body[data-screen="app"] #app-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- PIN-экран --- */

.gate-pin { max-width: 320px; text-align: center; }
.gate-pin .gate-title, .gate-pin .gate-sub { text-align: center; }

.pin-dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-height: 16px;
  margin: 22px 0 8px;
}
.pin-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid var(--text-dim);
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}
.pin-dot.on {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.05);
}

.pin-error { text-align: center; min-height: 16px; margin: 0 0 10px; }

.pin-keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 6px 0 8px;
}
.pin-key {
  height: 62px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 22px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.05s;
}
.pin-key:hover { border-color: var(--accent); color: var(--accent); }
.pin-key:active { transform: scale(0.96); background: var(--accent-tint); }
.pin-key-aux { font-size: 18px; color: var(--text-dim); }
.pin-key-ok { font-size: 20px; }
.pin-key-ok:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.pin-key-ok:disabled { opacity: 0.3; cursor: not-allowed; }
.pin-key-ok:disabled:hover { border-color: var(--border); color: var(--text); }

/* --- ворота (активация/блокировка/recovery) --- */

.gate {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 34px 30px;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.gate-wide { max-width: 560px; }

.gate-title {
  font-size: 18px;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
  color: var(--text);
}
.gate-sub {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-dim);
  margin-bottom: 22px;
}

.gate-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13.5px;
  padding: 12px 14px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.15s;
}
.gate-input:focus { border-color: var(--accent); }
.gate-input::placeholder { color: var(--text-dim); }

.gate-btn {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: 9px;
  color: var(--bg);
  font-family: var(--mono);
  font-size: 13.5px;
  font-weight: 600;
  padding: 12px 14px;
  margin-top: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.gate-btn:hover { opacity: 0.9; }
.gate-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.gate-btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  margin-top: 10px;
}

.gate-link {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  padding: 12px 0 0;
  cursor: pointer;
  text-align: center;
}
.gate-link:hover { color: var(--accent); }

.gate-error {
  color: rgb(255, 120, 120);
  font-size: 12px;
  min-height: 16px;
  margin-top: 10px;
}

.pw-meter {
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
  margin: -4px 0 6px;
}
.pw-meter > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s, background 0.2s; }
.pw-meter.s0 > span, .pw-meter.s1 > span { background: rgb(255, 120, 120); }
.pw-meter.s2 > span { background: rgb(230, 190, 90); }
.pw-hint { font-size: 11px; color: var(--text-dim); min-height: 14px; margin-bottom: 8px; }

.gate-check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 16px 0 6px;
  cursor: pointer;
}
.gate-check input { margin-top: 2px; accent-color: var(--accent); }

.recovery-key {
  font-family: var(--mono);
  font-size: 12.5px;
  word-break: break-all;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 9px;
  padding: 14px;
  color: var(--accent);
  line-height: 1.6;
  user-select: all;
}

.pinpad { margin-top: 4px; }

/* --- палитра ⌘K и настройки --- */

.palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 2000;
}
.palette-overlay.open { display: flex; }

.palette, .settings-sheet {
  width: 100%;
  max-width: 560px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.palette-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  padding: 16px 18px;
  outline: none;
}
.palette-results { max-height: 50vh; overflow-y: auto; }
.palette-item {
  padding: 11px 18px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.palette-item:hover { background: var(--accent-tint); }
.palette-name { font-size: 13px; color: var(--text); }
.palette-path { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.palette-empty { padding: 18px; color: var(--text-dim); font-size: 12.5px; }

.settings-sheet { padding: 8px; }
.settings-title { padding: 12px 14px 8px; font-size: 13px; color: var(--text-dim); }
.settings-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 11px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.settings-item:hover { background: var(--accent-tint); color: var(--accent); }
.settings-note { padding: 10px 14px; font-size: 11.5px; color: var(--text-dim); line-height: 1.6; }

.status-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 6px;
}
.status-btn:hover { color: var(--accent); }

.app {
  width: 100%;
  max-width: 1200px;
  height: min(760px, 92vh);
  display: flex;
  gap: 12px;
}

.tables-panel {
  width: 168px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow-y: auto;
  padding: 10px 8px;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.table-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 2px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}

.table-item:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }

.table-item.active {
  color: var(--accent);
  background: var(--accent-tint);
}

.table-item .label {
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-item .label[contenteditable="true"] { color: var(--accent); border-bottom: 1px solid var(--accent); }

.table-add {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  transition: color 0.15s;
}

.table-add:hover { color: var(--accent); }

.window {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* --- вкладки --- */

.tabbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.tab {
  display: flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
  letter-spacing: 0.02em;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}

.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }

.tab.active {
  color: var(--accent);
  background: var(--accent-tint);
}

.tab .label { outline: none; }
.tab .label[contenteditable="true"] { color: var(--accent); border-bottom: 1px solid var(--accent); }

.tab-add {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  transition: color 0.15s;
}

.tab-add:hover { color: var(--accent); }

/* --- корпус --- */

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 10px 8px;
}

.item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 2px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}

.item:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }

.item.active {
  color: var(--accent);
  background: var(--accent-tint);
}

.item .label {
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item .label[contenteditable="true"] { color: var(--accent); border-bottom: 1px solid var(--accent); }

.item-add {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  transition: color 0.15s;
}

.item-add:hover { color: var(--accent); }

/* --- редактор --- */

.editor {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.75;
  padding: 30px 40px;
  caret-color: var(--accent);
}

.editor::placeholder { color: var(--text-dim); }
.editor::selection, .editor *::selection { background: var(--accent); color: var(--bg); }

/* --- статусбар --- */

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  height: 34px;
  padding: 0 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
}

.statusbar .crumb { overflow: hidden; text-overflow: ellipsis; }
.statusbar .sep { color: var(--accent); }

.statusbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.savestate { transition: color 0.2s; }
.savestate.saving { color: var(--accent); }
.savestate.saving .dot { animation: savestate-pulse 1s ease-in-out infinite; }
.savestate.error { color: rgb(255, 120, 120); }

@keyframes savestate-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* --- контекстное меню --- */

.context-menu {
  position: fixed;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  min-width: 170px;
  font-size: 12.5px;
  font-family: var(--mono);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  z-index: 1000;
}

.context-menu-item {
  padding: 8px 12px;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, color 0.12s;
}

.context-menu-item:hover {
  background: var(--accent-tint);
  color: var(--accent);
}

.context-menu-item.danger { color: rgba(255, 120, 120, 0.85); }
.context-menu-item.danger:hover {
  background: rgba(255, 90, 90, 0.12);
  color: rgb(255, 140, 140);
}

/* --- скроллбары --- */

.editor::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.tabbar::-webkit-scrollbar,
.tables-panel::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.editor::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb,
.tabbar::-webkit-scrollbar-thumb,
.tables-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

.editor::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover,
.tables-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.16);
}
