@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap");

:root {
  --navy: #162130;
  --navy-deep: #0e1620;
  --cream: #f2f1ef;
  --silver: #b0bac5;
  --ink: #162130;
  --ink-soft: #5c6b7a;
  --line: rgba(22, 33, 48, 0.12);
  --brand: #162130;
  --danger: #8b3a32;
  --ok: #2f6f4e;
  --warn: #8a5a12;
  --surface: #f2f1ef;
  --panel: #162130;
  --sans: "DM Sans", "Avenir Next", "Segoe UI", sans-serif;
  color-scheme: light;
}

html.dark {
  --navy: #0e1620;
  --navy-deep: #080d13;
  --cream: #121a24;
  --silver: #b0bac5;
  --ink: #e8eef4;
  --ink-soft: #9aabbc;
  --line: rgba(176, 186, 197, 0.18);
  --brand: #e8eef4;
  --danger: #e8a39c;
  --ok: #8fcdb0;
  --warn: #e0c48a;
  --surface: #121a24;
  --panel: #080d13;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { overflow-x: hidden; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--surface);
  line-height: 1.5;
  font-size: 15px;
}
a { color: inherit; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.03em; margin: 0 0 0.75rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 500; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  max-width: 100%;
}
.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 2.4rem 0;
  min-width: 0;
}
.status { font-weight: 500; letter-spacing: 0.02em; }
.status-ok { color: var(--ok); }
.status-bad { color: var(--danger); }
.status-muted { color: var(--ink-soft); }
.impersonation-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  min-width: 0;
  font-size: 0.88rem;
}
.impersonation-bar form { margin: 0; }
.metric-bars {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  height: 120px;
}
.metric-bar {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 0.3rem;
}
.metric-bar span {
  display: block;
  width: 100%;
  max-width: 2rem;
  min-height: 4px;
  border-radius: 8px 8px 2px 2px;
  background: var(--navy);
}
html.dark .metric-bar span { background: var(--silver); }
.metric-bar small { color: var(--ink-soft); font-size: 0.68rem; }
.account-menu { position: relative; min-width: 0; }
.account-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  max-width: 16rem;
  padding: 0.25rem 0.7rem 0.25rem 0.25rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.account-trigger:hover, .account-menu.open .account-trigger { border-color: var(--navy); }
html.dark .account-trigger:hover, html.dark .account-menu.open .account-trigger { border-color: var(--silver); }
.account-avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  background: var(--navy);
  color: var(--cream);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
html.dark .account-avatar { background: #e8eef4; color: #162130; }
.account-warn {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--warn);
  box-shadow: 0 0 0 2px var(--surface);
}
.account-meta { min-width: 0; }
.account-name {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-sub {
  display: block;
  font-size: 0.68rem;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}
.account-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  width: 16.5rem;
  z-index: 50;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  padding: 0.35rem 0;
  box-shadow: 0 16px 40px rgba(14, 22, 32, 0.12);
}
.account-menu.open .account-dropdown { display: block; }
.account-dropdown-head {
  padding: 0.7rem 1rem 0.65rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.25rem;
}
.account-dropdown-head p { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.muted-inline { color: var(--ink-soft); font-size: 0.82rem; font-weight: 400; }
.account-dropdown a,
.account-dropdown button[type="submit"],
.account-dropdown .theme-toggle.menu {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  border-radius: 0;
}
.account-dropdown a:hover,
.account-dropdown button[type="submit"]:hover,
.account-dropdown .theme-toggle.menu:hover {
  background: rgba(22, 33, 48, 0.06);
}
html.dark .account-dropdown a:hover,
html.dark .account-dropdown button[type="submit"]:hover,
html.dark .account-dropdown .theme-toggle.menu:hover {
  background: rgba(232, 238, 244, 0.06);
}
.theme-toggle.menu {
  width: 100%;
  margin: 0;
  border-radius: 0;
  border: 0;
  justify-content: flex-start;
  color: inherit;
}
.nav {
  background: var(--panel);
  color: var(--silver);
  padding: 2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  max-width: 260px;
  overflow: hidden;
}
.nav a {
  color: var(--silver);
  text-decoration: none;
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  border: 1px solid transparent;
  letter-spacing: 0.04em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav a:hover, .nav a.active { border-color: var(--silver); color: #e8eef4; }
.brand {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 2rem; color: #e8eef4; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; font-size: 0.92rem;
  min-width: 0;
}
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand img { width: 32px; height: 32px; object-fit: contain; flex-shrink: 0; }
.nav .muted {
  color: var(--silver);
  font-size: 0.68rem;
  margin: 1.6rem 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}
.nav-foot {
  margin-top: auto;
  padding-top: 1.4rem;
  min-width: 0;
  width: 100%;
}
.nav-user {
  margin-top: 0.85rem;
  min-width: 0;
  max-width: 100%;
  color: var(--silver);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: none;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
}
.nav-user strong {
  display: block;
  font-weight: 600;
  color: #e8eef4;
  margin-bottom: 0.15rem;
}
.main {
  padding: 2.4rem 2.6rem 3.5rem;
  max-width: 1100px;
  min-width: 0;
  overflow-x: hidden;
}
.card {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.1rem;
  min-width: 0;
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.1rem;
}
.page-head h1 { margin-bottom: 0.35rem; }
.page-head p { margin: 0; }
.page-head .btn { flex-shrink: 0; margin-top: 0.15rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.stat { flex: 1; min-width: 150px; }
.stat small { display: block; font-size: 0.72rem; color: var(--ink-soft); font-weight: 400; letter-spacing: 0; margin-top: 0.35rem; text-transform: none; }
.sms-inline { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem 0.7rem; align-items: end; margin-top: 0.9rem; }
.sms-inline label { grid-column: 1 / -1; margin-top: 0; }
.sms-inline input { margin: 0; }
.sms-inline .btn { margin: 0; white-space: nowrap; }
label {
  display: block; font-size: 0.7rem; margin: 0.85rem 0 0.35rem;
  color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.14em;
}
input, select, textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font: inherit;
  color: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--navy); }
html.dark input:focus, html.dark select:focus, html.dark textarea:focus { border-color: var(--silver); }
textarea { border-radius: 16px; min-height: 90px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: 1px solid var(--navy); cursor: pointer; text-decoration: none;
  background: var(--navy); color: var(--cream); padding: 0.65rem 1.15rem;
  border-radius: 999px; font: inherit; font-weight: 500; letter-spacing: 0.04em;
}
html.dark .btn {
  background: transparent;
  color: var(--silver);
  border-color: var(--silver);
}
.btn.secondary, .btn.ghost {
  background: transparent; color: var(--navy);
}
html.dark .btn.secondary, html.dark .btn.ghost { color: var(--silver); }
.nav .btn.ghost { color: var(--silver); border-color: var(--silver); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.flash { padding: 0.8rem 1rem; border-radius: 999px; margin-bottom: 1rem; border: 1px solid var(--line); }
.flash.success { color: var(--ok); }
.flash.error { color: var(--danger); }
.flash.info { color: var(--warn); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.75rem 0.85rem 0.75rem 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); font-weight: 500; }
.table-scroll { overflow-x: auto; min-width: 0; }
.data-table { table-layout: auto; width: 100%; }
.data-table th,
.data-table td { padding: 0.8rem 0.85rem; vertical-align: middle; }
.data-table th:first-child,
.data-table td:first-child { padding-left: 0; }
.data-table th:last-child,
.data-table td:last-child { padding-right: 0; }
.col-stub { width: 1%; white-space: nowrap; max-width: 16rem; }
.col-dest { width: 99%; min-width: 8rem; }
.col-clicks,
.col-prot,
.col-status,
.col-actions { width: 1%; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.short-url {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  max-width: 10.5rem;
}
.copy-row.compact { flex-wrap: nowrap; gap: 0.7rem; }
.copy-row.compact .mono,
.copy-row.compact .short-url {
  flex: 0 1 auto;
  min-width: 0;
  overflow-wrap: normal;
}
.copy-row.compact .btn {
  flex-shrink: 0;
  padding: 0.3rem 0.75rem;
  font-size: 0.75rem;
}
.dest-cell {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  max-width: 100%;
}
.dest-preview {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
  font-size: 0.88rem;
}
.icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-btn svg { width: 0.85rem; height: 0.85rem; }
.icon-btn:hover { color: var(--ink); border-color: var(--ink); }
html.dark .icon-btn:hover { color: var(--cream); border-color: var(--silver); }
.row-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: nowrap;
  justify-content: flex-start;
  white-space: nowrap;
}
.row-actions a {
  flex-shrink: 0;
}
.row-actions form { margin: 0; flex-shrink: 0; }
.row-actions .btn { padding: 0.3rem 0.7rem; font-size: 0.75rem; }
.url-modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(36rem, calc(100vw - 2rem));
}
.url-modal.create-modal { max-width: min(28rem, calc(100vw - 2rem)); }
.create-modal .url-modal-box form > label:first-of-type { margin-top: 0.15rem; }
.create-modal .url-modal-box p {
  margin: 1.05rem 0 0;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.url-modal::backdrop { background: rgba(8, 13, 19, 0.55); }
.url-modal-box {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.25rem 1.35rem 1.15rem;
  box-shadow: 0 18px 48px rgba(8, 13, 19, 0.28);
}
.dest-full {
  margin: 0 0 1rem;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 0.88rem;
  line-height: 1.45;
}
.url-modal-box textarea {
  min-height: 7.5rem;
  margin-bottom: 0.4rem;
}

.gate {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  padding: 0;
  background: var(--panel);
  overflow: hidden;
  max-width: 100%;
}
.gate-dark {
  background: var(--panel);
  color: var(--silver);
  min-height: 100vh;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3.5rem clamp(1.5rem, 8%, 4.5rem);
}
.gate-light {
  background: var(--cream);
  min-height: 100vh;
  min-width: 0;
  overflow: hidden;
}
html.dark .gate-light { background: #cfc9c2; }
.gate-dark h1 { color: #e8eef4; }
.gate-dark input {
  border-color: var(--silver);
  color: #e8eef4;
}
.gate-dark label { color: var(--silver); }
.gate-dark .btn {
  background: transparent;
  color: var(--silver);
  border-color: var(--silver);
}
.gate-dark a { color: var(--silver); }
.gate-foot {
  margin-top: 2.5rem;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.hero {
  width: 100%;
  max-width: 26rem;
  min-width: 0;
}
.hero input, .hero select, .hero textarea, .hero .btn {
  max-width: 100%;
}
.packs { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.8rem; }
.pack { border: 1px solid var(--line); border-radius: 18px; padding: 1rem; }
.qr { width: 168px; height: 168px; background: #fff; border-radius: 12px; }
.copy-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; min-width: 0; }
.copy-row .mono, .copy-row a { min-width: 0; overflow-wrap: anywhere; }
.copy-row .btn { padding: 0.35rem 0.8rem; font-size: 0.78rem; }
.docs-tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0 0 1.1rem; }
.docs-pre {
  margin: 0;
  overflow: auto;
  max-height: 70vh;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.82rem;
  line-height: 1.45;
}
.stub-field { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.stub-field span { color: var(--ink-soft); white-space: nowrap; }
.stub-field input { flex: 1; min-width: 0; }
.ol-plain { padding-left: 1.1rem; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--silver);
  background: transparent;
  color: var(--silver);
  font: inherit;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  margin-bottom: 0.7rem;
}
.theme-toggle svg { width: 1rem; height: 1rem; flex-shrink: 0; }
.theme-toggle.float {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 40;
  width: auto;
  margin: 0;
  min-width: 2.75rem;
  height: 2.75rem;
  padding: 0 0.95rem;
  background: #f2f1ef;
  color: #162130;
  border-color: #162130;
  box-shadow: 0 8px 24px rgba(8, 13, 19, 0.18);
}
.theme-toggle .theme-label-dark,
html.dark .theme-toggle .theme-label-light { display: none; }
html.dark .theme-toggle .theme-label-dark { display: inline; }
.theme-toggle .icon-sun { display: none; }
html.dark .theme-toggle .icon-sun { display: block; }
html.dark .theme-toggle .icon-moon { display: none; }

@media (max-width: 860px) {
  .shell, .gate { grid-template-columns: minmax(0, 1fr); }
  .gate-light { display: none; }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    max-width: none;
  }
  .nav-foot { width: 100%; margin-top: 0.6rem; padding-top: 0.4rem; }
  .theme-toggle.float { top: 0.7rem; right: 0.7rem; }
  .topbar { padding: 0.9rem 1.2rem 0; }
  .account-meta { display: none; }
  .main { padding: 1.4rem 1.2rem 3rem; }
}
