@font-face {
  font-family: "Hanken Grotesk";
  src: url("/fonts/hanken-grotesque.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage-grotesque.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #17171c;
  --rail: #131318;
  --surface: #20202a;
  --surface-raised: #23232e;
  --hover: #2a2a35;
  --line: #ffffff21;
  --line-soft: #ffffff12;
  --text: #f3f2f7;
  --muted: #b1b0bf;
  --accent: #2e9bff;
  --accent-light: #bfe3ff;
  --accent-surface: #202b3e;
  --ink: #121925;
  --positive: #b1e97d;
  --warning: #f1ca83;
  --negative: #ffa9a5;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Hanken Grotesk", system-ui, sans-serif;
  font-family: var(--body);
  font-synthesis: none;
  background: var(--bg);
  color: var(--text);
  caret-color: var(--accent);
  scrollbar-color: #606070 var(--rail);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 300px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; }
a { color: var(--accent-light); text-underline-offset: 0.2em; }
a:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { color: var(--ink); background: var(--accent-light); }

.visually-hidden, .skip:not(:focus) {
  clip-path: inset(50%);
  height: 1px;
  width: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
}
.skip {
  position: fixed;
  z-index: 2;
  top: 10px;
  left: 10px;
  padding: 8px 12px;
  background: var(--rail);
}

.sign-in {
  min-height: 100vh;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 24px;
}
.sign-in-panel {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: clamp(24px, 6vw, 40px);
}
.sign-in-panel h1 { margin: 0 0 12px; }
.sign-in-panel p { color: var(--muted); margin-bottom: 22px; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 212px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 30px;
  background: var(--rail);
  border-right: 1px solid var(--line);
  padding: 26px 16px 20px;
}
.brand {
  font: 700 21px/1.2 var(--display);
  letter-spacing: -0.025em;
  padding-inline: 10px;
}
.brand span {
  color: var(--muted);
  font: 650 0.74rem/1 var(--body);
  margin-left: 5px;
}
.sidebar nav { display: grid; gap: 4px; }
.nav-item {
  color: var(--muted);
  background: transparent;
  text-align: left;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 9px 11px;
  min-height: 44px;
  font-weight: 650;
}
.nav-item:hover { color: var(--text); background: var(--surface); }
.nav-item[aria-current="page"] {
  color: var(--accent-light);
  background: var(--accent-surface);
  border-color: #2e9bff44;
}
.session {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.session-name {
  color: var(--muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}
.session-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.legend {
  width: min(520px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
.legend::backdrop { background: #101015bc; }
.legend-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.legend dl { display: grid; gap: 4px; margin: 16px 0 0; }
.legend dt { margin-top: 8px; font-weight: 720; }
.legend dd { margin: 0; color: var(--muted); }

.workspace {
  width: min(100%, 1580px);
  min-width: 0;
  margin-inline: auto;
  padding: 28px clamp(18px, 3.2vw, 48px) 48px;
}
.page-head {
  display: grid;
  gap: 12px;
  margin-bottom: 22px;
}
h1, h2 {
  font-family: var(--display);
  font-weight: 740;
  line-height: 1.12;
  letter-spacing: -0.025em;
}
h1 { font-size: 2.125rem; margin: 0; }
h2 { font-size: 1.42rem; margin: 0; overflow-wrap: anywhere; }
h3 { font-size: 1rem; margin: 0 0 8px; }

.search {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px 16px;
}
.search-query {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  flex: 1 1 320px;
  max-width: 520px;
}
.search-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-field {
  display: grid;
  gap: 3px;
  min-width: 132px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}
.filter-field select {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 500;
}
input, select, textarea {
  width: 100%;
  min-width: 0;
  padding: 9px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0;
}
input, select { height: 44px; }
textarea { resize: vertical; min-height: 84px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:hover, select:not(:disabled):hover, textarea:hover { border-color: #ffffff50; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }
select:disabled { opacity: 0.55; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 650;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
}
.button:hover { background: var(--hover); color: var(--text); }
.button:disabled { color: var(--muted); cursor: default; opacity: 0.65; }
.button.primary { color: var(--ink); background: var(--accent); border-color: var(--accent); }
.button.primary:hover { color: var(--ink); background: #74bbff; border-color: #74bbff; }
.button.danger { color: var(--negative); }
.button.confirm-danger { border-color: var(--negative); }
.button.small { min-height: 40px; padding-inline: 10px; }

.workspace-content {
  display: grid;
  gap: 18px;
  align-items: start;
}
.workspace-content.has-detail {
  grid-template-columns: minmax(0, 1fr) minmax(330px, 0.83fr);
}
.directory, .detail { min-width: 0; }
.detail {
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  scrollbar-gutter: stable;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 19px;
}
.detail-head {
  display: grid;
  gap: 11px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.detail-nav { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; }
.detail-head p { color: var(--muted); overflow-wrap: anywhere; }
.detail-head .statuses { margin-top: 3px; }
.detail-section { padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--line); }
.detail-section > p { color: var(--muted); }
.detail-section p + p { margin-top: 8px; }
.detail .identity { padding-block: 14px; margin: 0; }
.identity > div {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr);
  align-items: baseline;
  gap: 8px;
  padding-block: 4px;
}
.identity dt { color: var(--muted); }
.identity dd { margin: 0; overflow-wrap: anywhere; }
.detail-list { list-style: none; padding: 0; margin: 0; }
.detail-list li {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line-soft);
  padding-block: 8px;
}
.detail-list li:last-child { border-bottom: 0; }
.detail-list .secondary { min-width: 0; }
.detail-list .row-link { min-height: 40px; width: 100%; }
.detail-item { display: grid; min-width: 0; gap: 1px; }
.detail-item .label { overflow-wrap: anywhere; }
.detail-list .row-meta { font-size: 0.875rem; }
.action-buttons, .statuses { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.action-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.action-form h3 { margin: 0; }
.action-form label { font-weight: 650; }
.action-form p { color: var(--muted); }
.action-form .action-buttons { margin-top: 2px; }
.preview-media {
  display: block;
  max-width: 100%;
  max-height: min(56vh, 520px);
  object-fit: contain;
  background: var(--rail);
  border: 1px solid var(--line);
  margin-bottom: 10px;
}

.table-frame {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 12px clamp(9px, 1.4vw, 18px); text-align: left; }
th {
  padding-block: 9px;
  color: var(--muted);
  background: var(--rail);
  font-size: 0.79rem;
  font-weight: 700;
}
th:first-child { width: 44%; }
.section-audit th:first-child { width: 26%; }
.section-tags th:first-child { width: 28%; }
.section-tags th:nth-child(2) { width: 36%; }
.section-legacy-tags th:first-child { width: 36%; }
.section-legacy-tags th:nth-child(2) { width: 40%; }
.tag-mobile-kind { display: none; }
td {
  border-top: 1px solid var(--line-soft);
  overflow-wrap: anywhere;
  font-size: 0.94rem;
}
tr:has(.row-link):hover td, tr.selected td { background: var(--surface-raised); }
.row-link {
  display: inline-grid;
  text-align: left;
  align-content: center;
  gap: 2px;
  cursor: pointer;
  min-height: 39px;
  min-width: 0;
  max-width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 3px 0;
  color: var(--text);
  font-weight: 720;
  overflow-wrap: anywhere;
  text-decoration: none;
}
.row-link:hover, .row-link[aria-current="true"] { color: var(--accent-light); }
.secondary, .row-meta { color: var(--muted); }
.row-meta { font-size: 0.82rem; font-weight: 450; }
.code, time { font-variant-numeric: tabular-nums; }
.code { font-family: ui-monospace, monospace; font-size: 0.79rem; }
.status {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 690;
  color: var(--muted);
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status.good { color: var(--positive); }
.status.warn { color: var(--warning); }
.status.bad { color: var(--negative); }

.notice, .list-status, .detail-status {
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}
.notice { margin-bottom: 14px; }
.notice[data-level="error"], .inline-error { color: var(--negative); }
.notice[data-level="success"] { color: var(--positive); }
.list-status .button, .detail-status .button { margin-top: 10px; }
.action-form .inline-error { color: var(--negative); }
.page-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
}

@media (max-width: 1100px) {
  .app { grid-template-columns: 174px minmax(0, 1fr); }
  .workspace { padding-inline: 20px; }
  .workspace-content.has-detail {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 0.85fr);
  }
}

@media (max-width: 900px) {
  .workspace-content.has-detail { grid-template-columns: 1fr; }
  .detail { max-height: none; }
}

@media (max-width: 700px) {
  .app { display: block; }
  .sidebar {
    position: static;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    height: auto;
    padding: 12px 14px 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { align-self: center; padding: 0; }
  .sidebar nav {
    grid-area: 2 / 1 / 3 / -1;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .nav-item { padding-inline: 6px; text-align: center; }
  .session { margin: 0; padding: 0; border: 0; }
  .session-name { display: none; }
  .workspace { padding: 21px 14px 32px; }
  .page-head { gap: 12px; }
  .search-query { max-width: none; }
  .search-filters { flex: 1 1 100%; }
  .filter-field { flex: 1 1 130px; }
  h1 { font-size: 1.83rem; }
  th, td { padding-inline: 8px; }
}

@media (max-width: 500px) {
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-accounts td .row-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .section-audit table { table-layout: auto; }
  .section-audit th { width: auto !important; }
  .section-audit td { font-size: 0.82rem; }
  .section-audit time { overflow-wrap: normal; }
  .section-tags th:first-child { width: 32%; }
  .section-tags th:nth-child(2) { width: 41%; }
  .section-tags th:nth-child(3), .section-tags td:nth-child(3) { display: none; }
  .tag-mobile-kind { display: block; }
  .detail { padding: 14px; }
  .identity > div { grid-template-columns: minmax(82px, 0.6fr) minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
