:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --surface-3: #eef4fb;
  --field: #ffffff;
  --nav: #061a40;
  --nav-2: #09224f;
  --ink: #102033;
  --ink-strong: #061a40;
  --muted: #637188;
  --faint: #8b97aa;
  --line: #d8e0ec;
  --line-strong: #b8c4d6;
  --primary: #005eb8;
  --primary-2: #00a3e0;
  --primary-soft: #e8f2fc;
  --gold: #c99a2e;
  --danger: #b42318;
  --danger-bg: #fff4f2;
  --danger-line: #f2b7af;
  --shadow: 0 20px 44px rgba(6, 26, 64, 0.1);
  --nav-shadow: 10px 0 28px rgba(6, 26, 64, 0.1);
  --font-body:
    "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    sans-serif;
  font-family: var(--font-body);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #051126;
    --surface: #0b1d38;
    --surface-2: #0f2748;
    --surface-3: #102b50;
    --field: #071831;
    --nav: #020b1c;
    --nav-2: #071a38;
    --ink: #d9e5f7;
    --ink-strong: #f4f8ff;
    --muted: #9aaac0;
    --faint: #74859e;
    --line: #243956;
    --line-strong: #38506f;
    --primary: #4aa7f5;
    --primary-2: #35c2ef;
    --primary-soft: #102f55;
    --gold: #dfb958;
    --danger: #ff978f;
    --danger-bg: #32191d;
    --danger-line: #6d383a;
    --shadow: 0 22px 54px rgba(0, 0, 0, 0.32);
    --nav-shadow: 10px 0 30px rgba(0, 0, 0, 0.26);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #051126;
  --surface: #0b1d38;
  --surface-2: #0f2748;
  --surface-3: #102b50;
  --field: #071831;
  --nav: #020b1c;
  --nav-2: #071a38;
  --ink: #d9e5f7;
  --ink-strong: #f4f8ff;
  --muted: #9aaac0;
  --faint: #74859e;
  --line: #243956;
  --line-strong: #38506f;
  --primary: #4aa7f5;
  --primary-2: #35c2ef;
  --primary-soft: #102f55;
  --gold: #dfb958;
  --danger: #ff978f;
  --danger-bg: #32191d;
  --danger-line: #6d383a;
  --shadow: 0 22px 54px rgba(0, 0, 0, 0.32);
  --nav-shadow: 10px 0 30px rgba(0, 0, 0, 0.26);
}

:root[data-theme="light"] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  z-index: 5;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2) 62%, var(--gold));
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(180deg, rgba(0, 94, 184, 0.18), transparent 42%),
    linear-gradient(135deg, var(--nav), var(--nav-2));
  box-shadow: var(--nav-shadow);
  color: #eef6ff;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px 18px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 2px;
  background: #ffffff;
  color: var(--nav);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: inset 0 -3px 0 var(--primary-2);
}

.brand h1,
.brand p,
.topbar h2,
.topbar p {
  margin: 0;
}

.brand h1 {
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.18;
}

.brand p {
  margin-top: 2px;
  color: rgba(238, 246, 255, 0.62);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-actions,
.tools,
.topbar-actions,
.modal-actions,
.card-actions,
.category-actions {
  display: flex;
  gap: 8px;
}

.sidebar-actions {
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.icon-btn {
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 2px;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  transition:
    transform 0.14s ease,
    border-color 0.14s ease,
    background-color 0.14s ease,
    color 0.14s ease,
    box-shadow 0.14s ease;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 94, 184, 0.22);
}

.primary-btn:hover {
  background: #004f9c;
  transform: translateY(-1px);
}

.ghost-btn {
  background: var(--field);
  border-color: var(--line-strong);
  color: var(--ink-strong);
}

.ghost-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

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

.danger-btn:hover {
  transform: translateY(-1px);
}

.sidebar .ghost-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: #eef6ff;
}

.sidebar .primary-btn {
  background: #ffffff;
  color: var(--nav);
  box-shadow: none;
}

.icon-btn {
  width: 30px;
  min-height: 30px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.category-list {
  display: grid;
  gap: 8px;
}

.category-block {
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.045);
}

.category-row,
.subcategory-row,
.third-category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.category-row {
  padding: 7px 7px 7px 9px;
  border-left: 3px solid transparent;
}

.subcategory-group {
  display: grid;
}

.subcategory-group[hidden] {
  display: none;
}

.subcategory-row {
  width: calc(100% - 14px);
  margin: 0 7px 7px;
  padding: 6px 6px 6px 10px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.055);
}

.third-category-group {
  display: grid;
}

.third-category-group[hidden] {
  display: none;
}

.third-category-row {
  width: calc(100% - 28px);
  margin: -1px 7px 7px 21px;
  padding: 5px 6px 5px 10px;
  border: 1px solid transparent;
  border-left-color: rgba(238, 246, 255, 0.16);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.035);
}

.category-list > .subcategory-row {
  width: 100%;
  margin: 0;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.16);
}

.category-name,
.subcategory-name,
.third-category-name {
  min-width: 0;
  flex: 1;
  border: 0;
  background: transparent;
  color: rgba(238, 246, 255, 0.92);
  text-align: left;
  padding: 2px 0;
}

.collapse-btn {
  display: grid;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  place-items: center;
  border: 1px solid rgba(238, 246, 255, 0.22);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(238, 246, 255, 0.82);
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  padding: 0;
}

.collapse-btn:hover {
  border-color: rgba(74, 167, 245, 0.58);
  background: rgba(74, 167, 245, 0.16);
  color: #fff;
}

.category-name {
  font-size: 13px;
  font-weight: 850;
}

.subcategory-name {
  color: rgba(238, 246, 255, 0.68);
  font-size: 12px;
  font-weight: 650;
}

.third-category-name {
  color: rgba(238, 246, 255, 0.56);
  font-size: 11px;
  font-weight: 650;
}

.active-scope {
  background: rgba(74, 167, 245, 0.18);
  border-color: rgba(74, 167, 245, 0.32);
}

.category-row.active-scope {
  border-left-color: var(--primary-2);
}

.third-category-row.active-scope {
  border-color: rgba(74, 167, 245, 0.28);
  border-left-color: var(--primary-2);
}

.category-actions {
  flex: 0 0 auto;
}

.mini-btn {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: rgba(238, 246, 255, 0.54);
}

.mini-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.content {
  min-width: 0;
  padding: 22px clamp(18px, 3vw, 34px) 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  margin-bottom: 14px;
}

.topbar-actions {
  align-items: center;
  flex-wrap: wrap;
  justify-content: end;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 22px;
  height: 2px;
  background: var(--gold);
}

.topbar h2 {
  color: var(--ink-strong);
  font-size: clamp(22px, 3vw, 34px);
  font-weight: 850;
  line-height: 1.05;
  letter-spacing: 0;
}

.theme-switch {
  display: inline-grid;
  grid-template-columns: repeat(3, max-content);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 6px 16px rgba(6, 26, 64, 0.05);
}

.theme-switch button {
  min-height: 30px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  font-size: 11px;
  font-weight: 850;
}

.theme-switch button:last-child {
  border-right: 0;
}

.theme-switch button.is-active {
  background: var(--primary);
  color: #fff;
}

.tools {
  align-items: end;
  flex-wrap: wrap;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 10px 24px rgba(6, 26, 64, 0.055);
  margin-bottom: 10px;
}

.search-box {
  flex: 1 1 340px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--field);
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.tools select {
  max-width: 190px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.summary-strip div {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  padding: 9px 11px 8px;
}

.summary-strip div::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--primary);
}

.summary-strip div:nth-child(2)::before {
  background: var(--nav-2);
}

.summary-strip div:nth-child(3)::before {
  background: var(--gold);
}

.summary-strip span {
  display: block;
  color: var(--ink-strong);
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.summary-strip small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.url-grid {
  display: grid;
  gap: 6px;
}

.url-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(180px, 1.25fr) minmax(220px, 1.6fr) minmax(92px, 0.46fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  border: 1px solid var(--line);
  border-left: 3px solid transparent;
  border-radius: 3px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(6, 26, 64, 0.045);
  padding: 7px 8px 7px 10px;
  transition:
    transform 0.14s ease,
    box-shadow 0.14s ease,
    border-color 0.14s ease,
    background-color 0.14s ease;
}

.url-card:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  border-left-color: var(--primary);
  box-shadow: 0 8px 20px rgba(6, 26, 64, 0.08);
}

.record-title {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  min-width: 0;
}

.record-heading {
  min-width: 0;
}

.url-card h3 {
  margin: 0 0 3px;
  color: var(--ink-strong);
  font-size: 13px;
  font-weight: 850;
  line-height: 1.18;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.url-link {
  display: block;
  color: var(--primary);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.2;
  overflow: hidden;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.url-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.tag {
  max-width: 86px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--gold) 36%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--gold) 12%, transparent);
  color: color-mix(in srgb, var(--gold) 72%, var(--ink-strong));
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 900;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.url-text {
  display: grid;
  gap: 2px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
}

.url-text p {
  margin: 0;
  overflow: hidden;
  line-height: 1.28;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.url-meta {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--faint);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.card-actions {
  justify-content: end;
}

.card-actions .ghost-btn,
.card-actions .danger-btn {
  min-height: 26px;
  padding: 0 8px;
  font-size: 11px;
}

.modal {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 4px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

#urlModal {
  width: min(1040px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(2, 11, 28, 0.58);
  backdrop-filter: blur(2px);
}

.modal-card {
  display: grid;
  gap: 11px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 18px;
  background: var(--surface);
}

.modal-card.wide {
  width: 100%;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  color: var(--ink-strong);
  font-size: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
}

.modal-card.wide .form-grid label:nth-child(2) {
  grid-column: span 2;
}

.text-grid {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
}

.modal-card.wide .text-grid label:nth-child(2) {
  grid-column: auto;
}

.modal-card input,
.modal-card select,
.modal-card textarea {
  padding: 7px 9px;
}

.modal-card textarea {
  min-height: 76px;
}

.modal-actions {
  position: sticky;
  bottom: -18px;
  justify-content: end;
  margin: 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px dashed var(--line-strong);
  border-radius: 3px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  text-align: center;
  padding: 28px;
}

.empty-state div {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 2px;
  background: var(--nav);
  color: #fff;
  font-size: 22px;
  margin-bottom: 10px;
}

.empty-state h3,
.empty-state p {
  margin: 0;
}

.empty-state h3 {
  color: var(--ink-strong);
  font-size: 20px;
}

.empty-state p {
  margin-top: 6px;
  color: var(--muted);
}

.portal-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(0, 94, 184, 0.12), transparent 42%),
    linear-gradient(315deg, rgba(201, 154, 46, 0.12), transparent 34%),
    var(--bg);
}

.portal-shell {
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(360px, 560px);
  width: min(980px, 100%);
  min-height: 540px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.portal-panel {
  display: grid;
  align-content: center;
  gap: 28px;
  padding: clamp(28px, 5vw, 48px);
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.portal-brand .brand-mark {
  background: var(--nav);
  color: #fff;
}

.portal-kicker {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.portal-brand h1 {
  margin: 0;
  color: var(--ink-strong);
  font-size: 25px;
  line-height: 1.1;
}

.portal-form {
  display: grid;
  gap: 14px;
}

.portal-form .primary-btn {
  width: 100%;
  min-height: 40px;
  margin-top: 4px;
}

.portal-error {
  min-height: 18px;
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.portal-aside {
  display: grid;
  align-content: end;
  gap: 26px;
  padding: clamp(28px, 5vw, 52px);
  background:
    linear-gradient(180deg, rgba(0, 163, 224, 0.14), transparent 45%),
    linear-gradient(135deg, var(--nav), var(--nav-2));
  color: #fff;
}

.portal-aside .eyebrow {
  color: rgba(238, 246, 255, 0.72);
}

.portal-aside h2 {
  max-width: 470px;
  margin: 0;
  color: #fff;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.02;
  letter-spacing: 0;
}

.portal-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.portal-metrics div {
  border-top: 2px solid rgba(255, 255, 255, 0.24);
  padding-top: 10px;
}

.portal-metrics span {
  display: block;
  color: var(--primary-2);
  font-size: 18px;
  font-weight: 900;
}

.portal-metrics small {
  display: block;
  margin-top: 4px;
  color: rgba(238, 246, 255, 0.7);
  font-size: 11px;
  font-weight: 850;
}

@media (max-width: 1040px) {
  .url-card {
    grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
  }

  .url-meta {
    display: none;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    box-shadow: none;
  }

  .content {
    padding: 18px 14px 30px;
  }

  .portal-shell {
    grid-template-columns: 1fr;
  }

  .portal-aside {
    min-height: 300px;
  }
}

@media (max-width: 680px) {
  .topbar,
  .sidebar-actions,
  .card-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: start;
  }

  .topbar-actions {
    justify-content: stretch;
    width: 100%;
  }

  .theme-switch {
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
  }

  .tools select {
    max-width: none;
  }

  .summary-strip,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal-card.wide .form-grid label:nth-child(2) {
    grid-column: auto;
  }

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

  .url-card {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .card-actions {
    flex-direction: row;
  }

  .portal-page {
    padding: 14px;
  }

  .portal-metrics {
    grid-template-columns: 1fr;
  }
}
