/* Link Hub - admin dashboard styles */
:root {
  --white: #FFFFFF; --g50: #F9FAFB; --g100: #F3F4F6; --g200: #E5E7EB; --g300: #D1D5DB; --g400: #9CA3AF; --g500: #6B7280; --g600: #4B5563; --g700: #374151;
  --ink: #111827; --green: #43E660; --green-h: #38D655; --green-soft: #E8FBEC; --green-ink: #0B6B22;
  --red: #DC2626; --red-soft: #FEE2E2; --blue-soft: #E0F2FE; --blue-ink: #0369A1;
  --r: 12px; --sh: 0 1px 2px rgba(17,24,39,.04), 0 1px 3px rgba(17,24,39,.06); --sh-lg: 0 20px 50px rgba(17,24,39,.18);
  --ring: 0 0 0 3px rgba(67,230,96,.35); --side: 248px; --t: .16s ease;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.adm { margin: 0; font: 14px/1.5 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; color: var(--ink); background: var(--g100); -webkit-font-smoothing: antialiased; }
.adm h1, .adm h2, .adm h3 { margin: 0; letter-spacing: -.01em; }
.adm h1 { font-size: 24px; font-weight: 700; line-height: 1.25; }
.adm h2 { font-size: 15px; font-weight: 600; }
.adm h3 { font-size: 16px; font-weight: 600; }
.adm p { margin: 0; }
.adm a { color: inherit; }
.adm code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--g100); padding: 2px 6px; border-radius: 6px; }
.muted { color: var(--g500); } .sm { font-size: 12px; } .center { text-align: center; }
.ic { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.side { position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--white); border-right: 1px solid var(--g200); display: flex; flex-direction: column; padding: 16px; gap: 16px; z-index: 30; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; font-weight: 700; font-size: 16px; padding: 4px; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; background: var(--green); color: var(--ink); display: grid; place-items: center; flex: none; }
.brand-mark.lg { width: 48px; height: 48px; border-radius: 14px; } .brand-mark.lg .ic { width: 24px; height: 24px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: 10px; text-decoration: none; color: var(--g600); font-weight: 500; transition: background-color var(--t), color var(--t); }
.nav a:hover { background: var(--g100); color: var(--ink); }
.nav a.on { background: var(--ink); color: var(--white); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.view-live { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px dashed var(--g300); border-radius: 10px; text-decoration: none; color: var(--g600); font-weight: 500; transition: var(--t); }
.view-live:hover { border-color: var(--ink); color: var(--ink); }
.me { display: flex; align-items: center; gap: 12px; padding-top: 12px; border-top: 1px solid var(--g200); }
.me-av { width: 36px; height: 36px; border-radius: 50%; background: var(--g100); display: grid; place-items: center; font-weight: 600; flex: none; }
.me-t { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.me-t strong, .me-t small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .me-t small { color: var(--g500); }
.main { margin-left: var(--side); padding: 32px; max-width: calc(1120px + var(--side)); display: flex; flex-direction: column; gap: 16px; min-height: 100vh; }
.topbar, .tabbar { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 8px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- Cards, forms, buttons ---------- */
.card { background: var(--white); border: 1px solid var(--g200); border-radius: var(--r); box-shadow: var(--sh); padding: 16px; }
.card > h2 { margin-bottom: 12px; }
.card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
.stack .field, .modal-body .field, .auth-card .field { margin-bottom: 0; }
.field > span, .field > legend { font-weight: 500; font-size: 13px; padding: 0; }
.field em { font-style: normal; font-weight: 400; }
.hint { color: var(--g500); font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=datetime-local], select, textarea {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--g300); border-radius: 10px; background: var(--white); color: var(--ink); font: inherit; transition: border-color var(--t), box-shadow var(--t);
}
textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: var(--ring); }
input[readonly] { background: var(--g50); }
input[type=range] { width: 100%; accent-color: var(--ink); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border: 1px solid var(--g300); border-radius: 10px; background: var(--white); color: var(--ink); font: 500 14px/1 'Inter', system-ui, sans-serif; text-decoration: none; cursor: pointer; white-space: nowrap; transition: background-color var(--t), border-color var(--t), transform var(--t), box-shadow var(--t); }
.btn:hover { background: var(--g50); border-color: var(--g400); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .seg button:focus-visible, .preset:focus-visible, .tabbar a:focus-visible, .nav a:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-primary { background: var(--green); border-color: var(--green); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(17,24,39,.1); }
.btn-primary:hover { background: var(--green-h); border-color: var(--green-h); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; } .btn-danger:hover { background: #B91C1C; border-color: #B91C1C; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--g600); } .btn-ghost:hover { background: var(--g100); border-color: transparent; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; } .btn-block { width: 100%; height: 44px; }
.btn[disabled] { opacity: .6; cursor: progress; }
.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--g500); cursor: pointer; text-decoration: none; transition: background-color var(--t), color var(--t); }
.icon-btn:hover { background: var(--g100); color: var(--ink); } .icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--g300); border-radius: 999px; transition: background-color var(--t); }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform var(--t); }
.switch input:checked + span { background: var(--green); } .switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { box-shadow: var(--ring); }
.row-switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 12px; border-top: 1px solid var(--g100); }
.row-switch > div { display: flex; flex-direction: column; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--g100); border-radius: 10px; max-width: 100%; }
.seg button { height: 32px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; color: var(--g600); font: 500 13px/1 'Inter', system-ui, sans-serif; cursor: pointer; transition: var(--t); white-space: nowrap; }
.seg button:hover { color: var(--ink); } .seg button.on { background: var(--white); color: var(--ink); box-shadow: var(--sh); }
.seg-4 { display: grid; grid-template-columns: repeat(4, 1fr); } .seg-4 button { padding: 0 4px; font-size: 12.5px; } .field .seg { display: flex; } .field .seg button { flex: 1; padding: 0 8px; }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--g100); color: var(--g600); }
.badge .ic { width: 12px; height: 12px; } .b-green { background: var(--green-soft); color: var(--green-ink); } .b-blue { background: var(--blue-soft); color: var(--blue-ink); }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 10px; font-size: 13px; }
.alert-err { background: var(--red-soft); color: #991B1B; } .alert .ic { margin-top: 1px; }

/* ---------- Links manager ---------- */
.url-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.url-card-t { display: flex; flex-direction: column; min-width: 0; } .url-card-t a { font-weight: 600; text-decoration: none; overflow-wrap: anywhere; } .url-card-t a:hover { text-decoration: underline; }
.list-card { padding: 0; overflow: hidden; }
.list-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid var(--g200); }
.link-list { list-style: none; margin: 0; padding: 0; }
.link-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--white); border-bottom: 1px solid var(--g100); transition: background-color var(--t); }
.link-row:last-child { border-bottom: 0; } .link-row:hover { background: var(--g50); }
.link-row.is-off .link-main, .link-row.is-off .link-thumb { opacity: .5; }
.link-row.ghost { background: var(--green-soft); } .link-row.chosen { box-shadow: var(--sh-lg); }
.drag { width: 28px; height: 36px; display: grid; place-items: center; color: var(--g400); cursor: grab; touch-action: none; border-radius: 8px; flex: none; }
.drag:hover { background: var(--g100); color: var(--ink); } .drag:active { cursor: grabbing; }
.link-thumb { width: 44px; height: 44px; border-radius: 10px; background: var(--g100); color: var(--g400); display: grid; place-items: center; overflow: hidden; flex: none; }
.link-thumb img { width: 100%; height: 100%; object-fit: cover; }
.link-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.link-title { font-weight: 600; cursor: text; border-radius: 6px; padding: 1px 4px; margin: -1px -4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; align-self: flex-start; max-width: 100%; transition: background-color var(--t); }
.link-title:hover { background: var(--g100); }
.inline-input { height: 30px; padding: 0 8px; font-weight: 600; border-radius: 8px; min-width: 180px; width: 100%; }
.link-url { color: var(--g500); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; align-items: center; }
.link-actions { display: flex; align-items: center; gap: 4px; flex: none; } .link-actions .switch { margin-left: 8px; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 16px; text-align: center; } .empty > .ic { width: 32px; height: 32px; color: var(--g400); }

/* ---------- Modal, toasts ---------- */
.modal { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 60; backdrop-filter: blur(2px); }
.modal.open { display: flex; animation: fade .15s ease; }
.modal-card { background: var(--white); border-radius: 16px; width: 100%; max-width: 520px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: var(--sh-lg); animation: pop .18s ease; }
.modal-card.sm { max-width: 400px; padding: 24px; gap: 8px; } .modal-card.sm .modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 16px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--g200); }
.modal-body { padding: 16px; overflow-y: auto; } .modal-foot { display: flex; justify-content: flex-end; gap: 12px; padding: 16px; border-top: 1px solid var(--g200); }
@keyframes fade { from { opacity: 0; } } @keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.thumb-up, .av-row { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; } .thumb-up { margin-bottom: 0; }
.thumb-prev { width: 56px; height: 56px; border-radius: 12px; background: var(--g100); color: var(--g400); display: grid; place-items: center; overflow: hidden; flex: none; } .thumb-prev img { width: 100%; height: 100%; object-fit: cover; }
.thumb-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sched { border: 1px solid var(--g200); border-radius: 12px; padding: 12px; } .sched legend { padding: 0 6px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--sh-lg); max-width: 360px; font-size: 13px; opacity: 0; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease; }
.toast.in { opacity: 1; transform: none; } .toast .ic { color: var(--green); } .toast.err .ic { color: #FCA5A5; }

/* ---------- Appearance ---------- */
.ap-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.ap-form { display: flex; flex-direction: column; gap: 16px; }
.ap-preview { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.mtabs { display: none; }
.av-prev { width: 72px; height: 72px; border-radius: 50%; background: var(--g100); overflow: hidden; display: grid; place-items: center; font-weight: 600; font-size: 24px; flex: none; } .av-prev img, .bg-prev img { width: 100%; height: 100%; object-fit: cover; }
.bg-prev { width: 72px; height: 96px; border-radius: 10px; background: var(--g100); overflow: hidden; flex: none; }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; margin-bottom: 16px; }
.preset { display: flex; flex-direction: column; gap: 8px; padding: 8px; border: 1px solid var(--g200); border-radius: 12px; background: var(--white); cursor: pointer; text-align: left; font: 500 12px/1.2 'Inter', sans-serif; color: var(--ink); transition: var(--t); }
.preset:hover { border-color: var(--g400); transform: translateY(-1px); } .preset.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.preset-sw { height: 64px; border-radius: 8px; background: linear-gradient(160deg, var(--pa), var(--pb)); display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 0 10px; }
.preset-sw i { display: block; height: 10px; border-radius: 4px; background: var(--pc); } .preset-sw i + i { background: transparent; border: 1.5px solid var(--pt); opacity: .7; }
.color { display: flex; gap: 8px; } .color input[type=color] { width: 44px; height: 44px; padding: 4px; border: 1px solid var(--g300); border-radius: 10px; background: var(--white); cursor: pointer; flex: none; } .color input[type=text] { font-family: ui-monospace, Menlo, monospace; text-transform: uppercase; }
.phone { width: 320px; height: 640px; border: 10px solid var(--ink); border-radius: 44px; background: #fff; overflow: hidden; position: relative; box-shadow: var(--sh-lg); }
.phone-notch { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 96px; height: 22px; background: var(--ink); border-radius: 0 0 14px 14px; z-index: 2; }
.phone-screen { height: 100%; overflow-y: auto; scrollbar-width: none; } .phone-screen::-webkit-scrollbar { display: none; }
.phone .lb { min-height: 100%; } .phone .lb-wrap { padding-top: 44px; } .phone .lb-link > a, .phone .lb-link__share { pointer-events: none; }
.phone .lb-avatar { width: 96px; height: 96px; font-size: 36px; }

/* ---------- Analytics ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.kpi { display: flex; flex-direction: column; gap: 4px; } .kpi strong { font-size: 28px; line-height: 1.2; font-weight: 700; letter-spacing: -.02em; }
.delta { font-style: normal; font-size: 12px; font-weight: 500; color: var(--g500); min-height: 18px; } .delta.up { color: var(--green-ink); } .delta.down { color: var(--red); }
.g-ch { gap: 16px; } .span-2 { grid-column: span 2; }
.chart { position: relative; height: 260px; } .chart.tall { height: 320px; }
.chart-card.empty-data .chart canvas { visibility: hidden; } .chart-card.empty-data .chart::after { content: 'No data for this period'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--g400); }
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.tbl { width: 100%; border-collapse: collapse; min-width: 480px; } .tbl th { text-align: left; font-weight: 500; font-size: 12px; color: var(--g500); padding: 8px 12px; border-bottom: 1px solid var(--g200); }
.tbl td { padding: 12px; border-bottom: 1px solid var(--g100); } .tbl tr:last-child td { border-bottom: 0; } .tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td small { display: block; color: var(--g500); max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { display: block; height: 4px; border-radius: 4px; background: var(--g100); margin-top: 6px; overflow: hidden; } .bar i { display: block; height: 100%; background: var(--green); border-radius: 4px; }
.heat-wrap { overflow-x: auto; } .heat { display: grid; grid-template-columns: 40px repeat(24, minmax(22px, 1fr)); gap: 3px; min-width: 640px; font-size: 11px; color: var(--g500); }
.heat .c { aspect-ratio: 1; border-radius: 4px; background: var(--g100); min-height: 22px; } .heat .l { display: flex; align-items: center; } .heat .h { text-align: center; }

/* ---------- Settings ---------- */
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.copy-row { display: flex; gap: 8px; margin: 12px 0; } .set-grid .card > .btn { margin-top: 12px; } .set-grid .card > p + p { margin-top: 8px; }

/* ---------- Auth screens ---------- */
.auth-body { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--white); border: 1px solid var(--g200); border-radius: 16px; box-shadow: var(--sh); padding: 32px 24px; display: flex; flex-direction: column; gap: 16px; }
.auth-card h1 { font-size: 22px; } .auth-brand { display: flex; } .auth-foot { font-size: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .ap-grid { grid-template-columns: 1fr; }
  .mtabs { display: inline-flex; padding: 3px; gap: 2px; background: var(--white); border: 1px solid var(--g200); border-radius: 10px; align-self: flex-start; }
  .mtabs button { height: 32px; padding: 0 16px; border: 0; border-radius: 8px; background: transparent; font: 500 13px/1 'Inter', sans-serif; color: var(--g600); cursor: pointer; } .mtabs button.on { background: var(--ink); color: #fff; }
  .ap-grid[data-view="edit"] .ap-preview, .ap-grid[data-view="preview"] .ap-form { display: none; }
  .ap-preview { position: static; }
}
@media (max-width: 900px) {
  .side { display: none; }
  .main { margin-left: 0; padding: 16px 16px 96px; max-width: none; }
  .topbar { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 20; padding: 12px 16px calc(12px); padding-top: calc(12px + env(safe-area-inset-top)); background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--g200); }
  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgba(255,255,255,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--g200); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 10px; text-decoration: none; color: var(--g500); font-size: 11px; font-weight: 500; transition: var(--t); } .tabbar a.on { color: var(--ink); background: var(--g100); } .tabbar a.on .ic { color: #16A34A; }
  .page-head h1 { font-size: 21px; } .page-head .btn-primary { width: 100%; } .head-actions { width: 100%; } .head-actions .seg { flex: 1; } .head-actions .seg button { flex: 1; }
  .kpis { grid-template-columns: 1fr; } .kpi { flex-direction: row; align-items: center; justify-content: space-between; } .kpi strong { font-size: 22px; } .delta { display: none; }
  .grid-2.g-ch, .set-grid { grid-template-columns: 1fr; } .span-2 { grid-column: auto; }
  .toasts { right: 12px; left: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); } .toast { max-width: none; }
  .modal { align-items: flex-end; padding: 0; } .modal-card { max-width: none; border-radius: 16px 16px 0 0; max-height: 92dvh; } .modal-card.sm { border-radius: 16px; margin: 16px; width: auto; }
  .link-row { padding: 12px; gap: 8px; } .link-actions .icon-btn { width: 32px; height: 32px; } .link-actions .switch { margin-left: 4px; } .link-thumb { width: 40px; height: 40px; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) { .link-actions .act-dup { display: none; } .phone { width: 300px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
