:root {
  --ink: #16211d;
  --muted: #66736d;
  --line: #dfe6e2;
  --surface: #ffffff;
  --canvas: #f5f7f5;
  --accent: #176b4b;
  --accent-dark: #0e5338;
  --accent-soft: #e7f3ed;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --shadow: 0 14px 40px rgba(22, 33, 29, .08);
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(circle at 88% 0, #e9f3ed 0, transparent 28rem), var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .45rem; font-size: clamp(1.85rem, 4vw, 2.6rem); line-height: 1.08; letter-spacing: -.04em; }
h2 { margin-bottom: .35rem; font-size: 1.2rem; letter-spacing: -.02em; }
h3 { margin-bottom: .35rem; }
.muted { color: var(--muted); }
.eyebrow { margin-bottom: .45rem; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.site-header { height: 70px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(24px, calc((100vw - 1180px) / 2)); border-bottom: 1px solid rgba(223,230,226,.9); background: rgba(255,255,255,.78); backdrop-filter: blur(14px); }
.brand { color: var(--ink); font-weight: 800; text-decoration: none; letter-spacing: -.02em; }
.app-shell { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 54px 0 80px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 2px 8px rgba(22,33,29,.025); }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 28px; }
.page-heading p:last-child { margin-bottom: 0; }
.page-actions { display: flex; gap: 10px; }

.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .65rem 1rem; border: 1px solid transparent; border-radius: 9px; font-weight: 750; transition: .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: none; }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button-primary { color: white; background: var(--accent); box-shadow: 0 5px 14px rgba(23,107,75,.16); }
.button-primary:hover { background: var(--accent-dark); }
.button-secondary { color: var(--ink); border-color: var(--line); background: white; }
.button-secondary:hover, .button-quiet:hover { background: #f0f4f2; }
.button-danger { color: white; background: var(--danger); }
.button-quiet { min-height: 36px; padding: .45rem .75rem; color: var(--muted); background: transparent; }
.button-small { min-height: 34px; padding: .4rem .7rem; font-size: .84rem; }
.button-wide { width: 100%; }
.icon-button { width: 36px; height: 36px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: 1.5rem; line-height: 1; }
.icon-button:hover { color: var(--ink); background: var(--canvas); }

.state-card { min-height: 52vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.state-card h1 { color: var(--ink); font-size: 1.7rem; }
.state-icon, .danger-icon { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 14px; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-weight: 900; }
.danger-icon { color: var(--danger); background: var(--danger-soft); }
.spinner { width: 22px; height: 22px; display: inline-block; border: 3px solid #cfd9d4; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-layout { min-height: calc(100vh - 200px); display: grid; place-items: center; }
.login-panel { width: min(100%, 390px); padding: 34px; display: grid; gap: 20px; box-shadow: var(--shadow); }
.login-panel h1 { margin-bottom: 2px; font-size: 1.6rem; }

.create-panel { margin-bottom: 24px; padding: 26px; box-shadow: var(--shadow); }
.api-keys-panel { margin-bottom: 24px; padding: 26px; box-shadow: var(--shadow); }
.api-keys-panel .panel-heading p:last-child { max-width: 650px; margin-bottom: 0; font-size: .87rem; }
.inline-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto; align-items: end; gap: 12px; max-width: 600px; }
.secret-box { display: grid; gap: 10px; margin-top: 20px; padding: 15px; border: 1px solid #b8d8c8; border-radius: 10px; background: var(--accent-soft); font-size: .86rem; }
.secret-value { display: flex; align-items: center; gap: 10px; }
.secret-value code { min-width: 0; flex: 1; overflow-wrap: anywhere; user-select: all; }
.compact-empty { padding: 28px 0 4px; text-align: center; }
.api-keys-panel .table-wrap { margin: 22px -26px -26px; border-top: 1px solid var(--line); }
.panel-heading { display: flex; justify-content: space-between; align-items: start; gap: 20px; margin-bottom: 22px; }
.kind-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 22px; padding: 0; border: 0; }
.kind-picker legend { margin-bottom: 8px; font-size: .87rem; font-weight: 750; }
.kind-picker label { position: relative; }
.kind-picker input { position: absolute; opacity: 0; }
.kind-picker span { height: 100%; display: flex; flex-direction: column; gap: 3px; padding: 15px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: .15s ease; }
.kind-picker small { color: var(--muted); line-height: 1.35; }
.kind-picker input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.kind-picker input:focus-visible + span { outline: 3px solid rgba(23,107,75,.25); outline-offset: 2px; }
.form-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }
.field-wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 7px; color: var(--ink); font-size: .87rem; font-weight: 750; }
.field em { color: var(--muted); font-style: normal; font-weight: 500; }
.field input, select { width: 100%; min-height: 44px; padding: .65rem .8rem; border: 1px solid #cbd5d0; border-radius: 9px; color: var(--ink); background: white; outline: none; transition: .15s ease; }
.field input:focus, select:focus, .search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23,107,75,.12); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.checkbox-field { display: inline-flex; align-items: center; gap: 9px; width: fit-content; color: var(--muted); font-size: .87rem; cursor: pointer; }
.checkbox-field input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.privacy-option { align-items: flex-start; grid-column: 1 / -1; }
.privacy-option input { margin-top: 2px; }
.privacy-option span { display: grid; gap: 2px; }
.privacy-option small { color: var(--muted); font-weight: 500; line-height: 1.35; }
.field-hint, .field-error { min-height: 1em; color: var(--muted); font-size: .75rem; font-weight: 500; }
.field-error { color: var(--danger); }
.upload-field { position: relative; }
.upload-field > input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-box { min-height: 82px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 12px; border: 1px dashed #aab9b2; border-radius: 9px; background: #fafcfb; cursor: pointer; }
.upload-box small { margin-top: 3px; color: var(--muted); font-weight: 500; }
.upload-field input:focus-visible + .upload-box { outline: 3px solid rgba(23,107,75,.2); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.alert { padding: 11px 13px; border-radius: 8px; font-size: .85rem; line-height: 1.45; }
.alert-error { color: #7a271a; border: 1px solid #f4c7c1; background: var(--danger-soft); }

.links-panel { overflow: hidden; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.toolbar h2 { margin-bottom: .2rem; }
.toolbar p { margin-bottom: 0; font-size: .83rem; }
.filters { display: flex; gap: 10px; }
.filters select { width: 145px; }
.search-box { min-width: min(300px, 35vw); display: flex; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid #cbd5d0; border-radius: 9px; background: white; }
.search-box input { width: 100%; min-height: 42px; padding: 0; border: 0; outline: 0; background: transparent; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 16px; color: var(--muted); background: #fafcfb; font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
td { max-width: 300px; padding: 15px 16px; border-top: 1px solid var(--line); vertical-align: middle; font-size: .87rem; }
tbody tr:hover { background: #fcfdfc; }
.link-cell { display: flex; align-items: center; gap: 8px; }
.link-stack { display: grid; gap: 5px; }
.internal-name { max-width: 240px; overflow: hidden; font-size: .82rem; text-overflow: ellipsis; white-space: nowrap; }
.short-link { max-width: 220px; overflow: hidden; color: var(--accent); font-weight: 750; text-overflow: ellipsis; text-decoration: none; white-space: nowrap; }
.destination { display: block; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.copy-button, .row-action { border: 0; border-radius: 7px; color: var(--muted); background: transparent; }
.copy-button { width: 29px; height: 29px; }
.copy-button:hover, .row-action:hover { color: var(--ink); background: #edf2ef; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: .28rem .52rem; border-radius: 999px; font-size: .72rem; font-weight: 750; white-space: nowrap; }
.badge-gif { color: #6938a7; background: #f3edfc; }
.badge-redirect { color: #175cd3; background: #eaf2ff; }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .78rem; }
.status::before { width: 7px; height: 7px; border-radius: 50%; background: #9ca9a3; content: ""; }
.status-enabled { color: var(--accent); }
.status-enabled::before { background: #2a9d69; }
.number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; justify-content: flex-end; gap: 3px; }
.row-action { padding: .4rem .5rem; font-size: .78rem; }
.row-action-danger:hover { color: var(--danger); background: var(--danger-soft); }
.table-state { min-height: 220px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 30px; text-align: center; color: var(--muted); }
.empty-state .state-icon { margin-bottom: 2px; }
.empty-state p { margin: 0; }
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 14px; padding: 16px 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; }

.dialog { width: min(540px, calc(100% - 32px)); padding: 26px; border: 1px solid var(--line); border-radius: 15px; color: var(--ink); background: white; box-shadow: 0 30px 90px rgba(10,25,18,.22); }
.dialog::backdrop { background: rgba(14,27,21,.48); backdrop-filter: blur(2px); }
.dialog-small { width: min(430px, calc(100% - 32px)); text-align: center; }
.dialog-small .danger-icon { margin-inline: auto; }
.dialog-small .form-actions { justify-content: center; }
.short-preview { margin-bottom: 20px; overflow: hidden; color: var(--accent); font-size: .85rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.logs-dialog { width: min(620px, calc(100% - 32px)); }
.logs-dialog .panel-heading { margin-bottom: 8px; }
.logs-table { max-height: 360px; border: 1px solid var(--line); border-radius: 9px; }
.logs-table td { font-variant-numeric: tabular-nums; }
.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 20; display: grid; gap: 8px; }
.toast { max-width: 380px; padding: 12px 16px; border-radius: 9px; color: white; background: #20332a; box-shadow: var(--shadow); font-size: .86rem; animation: toast-in .2s ease-out; }
.toast-error { background: #8c271d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 800px) {
  .app-shell { width: min(100% - 28px, 1180px); padding-top: 34px; }
  .site-header { padding-inline: 16px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .filters { width: 100%; }
  .search-box { min-width: 0; flex: 1; }
  .links-panel th:nth-child(3), .links-panel td:nth-child(3), .links-panel th:nth-child(5), .links-panel td:nth-child(5) { display: none; }
}

@media (max-width: 560px) {
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-actions { width: 100%; }
  .page-actions .button { flex: 1; }
  .create-panel { padding: 20px; }
  .api-keys-panel { padding: 20px; }
  .api-keys-panel .table-wrap { margin-inline: -20px; margin-bottom: -20px; }
  .inline-form { grid-template-columns: 1fr; }
  .secret-value { align-items: stretch; flex-direction: column; }
  .kind-picker, .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .filters { flex-direction: column; }
  .filters select { width: 100%; }
  .links-panel th:nth-child(2), .links-panel td:nth-child(2), .links-panel th:nth-child(4), .links-panel td:nth-child(4) { display: none; }
  .api-keys-panel th:nth-child(3), .api-keys-panel td:nth-child(3) { display: none; }
  td { padding-inline: 12px; }
  .row-action { font-size: 0; }
  .row-action::first-letter { font-size: .9rem; }
  .pagination { justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
