:root {
  --bg: #e6e9ee;
  --bg-side: #f3f5f7;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #5b6775;
  --line: #cfd6de;
  --line-strong: #b7c0ca;
  --navy: #1e3a5f;
  --navy-hover: #16304e;
  --copper: #c9783a;
  --command-bg: #eef4ef;
  --command-ink: #163226;
  --danger: #9b2c2c;
  --danger-bg: #f8eaea;
  --shadow: 0 10px 30px rgba(23, 32, 42, 0.08);
  --radius: 14px;
  --font: "Segoe UI", "Liberation Sans", "Noto Sans", sans-serif;
  --mono: "IBM Plex Mono", "Cascadia Code", "Liberation Mono", "Menlo", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

button, input, textarea, select {
  font: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--navy);
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 20;
}

.skip-link:focus { top: 12px; }

.app-header {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(240px, 1.4fr) auto;
  gap: 16px;
  align-items: center;
  padding: 16px 22px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrap input {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #f8fafb;
  border-radius: 999px;
  padding: 10px 42px 10px 40px;
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--navy);
  background: white;
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.12);
}

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--muted);
}

.search-wrap kbd {
  position: absolute;
  right: 12px;
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  background: white;
}

.header-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn {
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

.btn:hover { background: #f4f6f8; }

a.btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.btn.primary {
  background: var(--navy);
  border-color: var(--navy);
  color: white;
}

.btn.primary:hover { background: var(--navy-hover); }

.btn.ghost { background: transparent; }

.btn.danger {
  background: var(--danger-bg);
  border-color: #e2b6b6;
  color: var(--danger);
}

.btn.small { padding: 5px 8px; font-size: 0.85rem; }

.btn.copied,
.btn.primary.copied {
  background: #2f6f45;
  border-color: #2f6f45;
  color: white;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.safety-banner {
  margin: 0;
  padding: 8px 22px;
  background: #f4efe6;
  color: #5a3b1c;
  border-bottom: 1px solid #e4d7c5;
  font-size: 0.9rem;
}

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: calc(100vh - 118px);
}

.sidebar {
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  padding: 16px 10px;
}

.cat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.cat-btn:hover { background: #e7ebf0; }

.cat-btn.active {
  background: white;
  box-shadow: 0 0 0 1px var(--line);
  font-weight: 600;
}

.cat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.cat-name { flex: 1; min-width: 0; }

.cat-count {
  color: var(--muted);
  font-size: 0.8rem;
}

.main {
  padding: 16px 22px 40px;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.toolbar-filters {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.sort-wrap select {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 6px 10px;
  background: white;
}

.result-count {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.favorites-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.command-table {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-head,
.command-row {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(320px, 1.15fr);
}

.table-head {
  background: #f7f8fa;
  color: #3d4a58;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.command-row {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  align-items: start;
  gap: 18px;
}

.command-row:last-child { border-bottom: 0; }

.command-row:hover { background: #fbfcfd; }

.command-pane {
  min-width: 0;
}

.command-code {
  margin: 0 0 10px;
  padding: 12px 14px;
  background: var(--command-bg);
  color: var(--command-ink);
  border: 1px solid #d5e3d8;
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 0.92rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.command-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  background: #f3f5f7;
  border-radius: 999px;
  padding: 3px 8px;
}

.desc-title {
  margin: 0 0 6px;
  font-size: 1rem;
}

.desc-body,
.procedure {
  margin: 0;
  color: var(--ink);
}

.procedure {
  margin-top: 8px;
  color: #3d4a58;
}

.procedure strong {
  color: var(--navy);
  font-weight: 650;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 0;
}

.tag {
  font-size: 0.75rem;
  color: var(--muted);
  background: #eef2f6;
  border-radius: 999px;
  padding: 2px 8px;
}

.row-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.empty h2 {
  margin: 0 0 8px;
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--navy);
  color: white;
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 40;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-root[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 42, 0.42);
}

.modal {
  position: relative;
  width: min(640px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  background: white;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(23, 32, 42, 0.22);
  padding: 22px;
}

.modal.wide { width: min(820px, 100%); }

.modal h2 {
  margin: 0 0 6px;
}

.modal-lead {
  margin: 0 0 16px;
  color: var(--muted);
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
}

.form-grid input,
.form-grid textarea,
.form-grid select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fbfcfd;
}

.form-grid textarea {
  min-height: 88px;
  resize: vertical;
}

.form-grid .mono { font-family: var(--mono); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.library-actions,
.category-list {
  display: grid;
  gap: 10px;
}

.category-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.category-item > div:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.help-list {
  margin: 0 0 16px;
  padding-left: 18px;
  color: #3d4a58;
}

.help-heading {
  margin: 8px 0 8px;
  font-size: 1rem;
}

.help-list kbd {
  font-size: 0.78rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  background: #f7f8fa;
}

.empty .btn { margin-top: 8px; }

@media (max-width: 980px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }

  #category-nav {
    display: flex;
    gap: 6px;
    min-width: max-content;
  }

  .table-head,
  .command-row {
    grid-template-columns: 1fr;
  }

  .table-head div:last-child { display: none; }

  .row-actions { opacity: 1; }
}
