:root {
  --bg: #14171c;
  --bg-raised: #1b1f26;
  --bg-card: #20242c;
  --border: #2a2f38;
  --text: #e6e9ef;
  --text-dim: #9aa3af;
  --accent: #7c9eff;
  --accent-dim: #3d4a70;
  --danger: #ff6b6b;
  --btn-text: #0e1116;
  --radius: 14px;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

/* Светлая тема — включается через data-theme на <html>, ставит app.js
   (localStorage, или автоопределение системной при первом заходе). */
:root[data-theme="light"] {
  --bg: #f2f3f6;
  --bg-raised: #ffffff;
  --bg-card: #ffffff;
  --border: #dde1e8;
  --text: #1a1d23;
  --text-dim: #676f7d;
  --accent: #3d5fdb;
  --accent-dim: #e2e8fc;
  --danger: #d9394f;
  --btn-text: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: 96px;
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
}

.theme-toggle {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:active { transform: scale(.92); }

.search-wrap { display: flex; }

#search {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px; /* не даёт iOS зумить при фокусе */
  outline: none;
}
#search:focus { border-color: var(--accent); }

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 64px;
  z-index: 9;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  white-space: nowrap;
}
.tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

#list {
  padding: 12px 16px 8px;
}

.category-section { margin-bottom: 18px; }

.category-heading {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  margin: 4px 0 8px;
  padding-left: 2px;
}

.card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
  min-height: 44px;
}

.card-text {
  flex: 1 1 auto;
  min-width: 0;
}

.card-command {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--accent);
  display: block;
}

.card-desc-preview {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-badge {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  padding: 3px 8px;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 16px;
}
.hidden { display: none !important; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--btn-text);
  font-size: 28px;
  line-height: 1;
  border: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  z-index: 20;
}
.fab:active { transform: scale(.94); }

/* Bottom-sheet модалки на dialog */
dialog.sheet {
  border: none;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 560px;
  background: transparent;
  color: var(--text);
}
dialog.sheet::backdrop {
  background: rgba(0,0,0,.55);
}
.sheet-inner {
  background: var(--bg-raised);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 20px 18px max(20px, env(safe-area-inset-bottom));
  max-height: 86vh;
  overflow-y: auto;
  position: relative;
  border: 1px solid var(--border);
  border-bottom: none;
  transition: transform .2s ease;
}

.sheet-handle {
  box-sizing: content-box;
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: -10px auto 10px;
  touch-action: none;
  /* увеличенная невидимая зона захвата, чтобы легче попасть пальцем */
  padding: 14px 40px;
  background-clip: content-box;
}
@media (min-width: 640px) {
  dialog.sheet { margin: auto; }
  .sheet-inner { border-radius: 20px; border-bottom: 1px solid var(--border); max-height: 80vh; }
}

.sheet-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
}

.sheet-title {
  font-size: 16px;
  margin: 0 32px 16px 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 32px 14px 0;
}

.card-command-big {
  font-family: var(--mono);
  font-size: 20px;
  color: var(--accent);
  word-break: break-word;
}

.badge {
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  padding: 3px 8px;
  flex: 0 0 auto;
}

.card-description {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  margin: 0 0 16px;
  white-space: pre-wrap;
}

.card-example-wrap { margin-bottom: 16px; }
.card-example-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.card-example {
  font-family: var(--mono);
  font-size: 13.5px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 10px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}
.tag-chip {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}

.btn-primary, .btn-secondary, .btn-danger {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  min-height: 44px;
}
.btn-primary { background: var(--accent); color: var(--btn-text); }
.btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.btn-secondary.copied { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); margin-top: 4px; }

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin: 14px 0 6px;
}
.field-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  font-family: var(--sans);
  resize: vertical;
}
.field-input.mono { font-family: var(--mono); font-size: 14px; }
.field-input:focus { outline: none; border-color: var(--accent); }

#add-form .btn-primary { margin-top: 20px; }

@media (min-width: 640px) {
  body { max-width: 720px; margin: 0 auto; }
}
