:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --bg-muted: #f4f4f5;
  --line: #e4e4e7;
  --line-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #a1a1aa;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --ok: #16a34a;
  --bad: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg-soft); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.w-full { width: 100%; }
.mono { font-family: var(--mono); }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--bg); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 8px 14px; letter-spacing: -.01em; }
.brand.big { font-size: 22px; justify-content: center; padding-bottom: 4px; }
.brand-logo { width: 30px; height: 30px; flex: none; }
.brand.big .brand-logo { width: 40px; height: 40px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--text); color: #fff; display: grid; place-items: center; font-size: 13px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a i { width: 16px; text-align: center; color: var(--text-3); }
.nav a:hover { background: var(--bg-muted); color: var(--text); }
.nav a.active { background: var(--bg-muted); color: var(--text); }
.nav a.active i { color: var(--text); }
.nav a .count { margin-left: auto; font-size: 12px; color: var(--text-3); }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 16px 10px 6px; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding-top: 12px; }
.main { padding: 26px 34px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.page-head .grow { flex: 1; }
.crumbs { display: flex; align-items: center; gap: 12px; font-size: 18px; font-weight: 500; }
.crumbs a { color: var(--text); }
.crumbs .sep { color: var(--text-3); font-size: 13px; }
.crumbs .globe { width: 30px; height: 30px; border-radius: 50%; background: var(--bg-muted); display: grid; place-items: center; font-size: 14px; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--bg-muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-dark { background: var(--text); color: #fff; border-color: var(--text); }
.btn-dark:hover { background: #3f3f46; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-danger { color: var(--bad); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 8px; border: 0; background: transparent; cursor: pointer; color: var(--text-2); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--bg-muted); color: var(--text); }
.input, .select, .textarea { width: 100%; height: 40px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 12px; font: inherit; background: var(--bg); color: var(--text); outline: none; transition: border-color .12s, box-shadow .12s; }
.textarea { height: auto; min-height: 110px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--text); box-shadow: 0 0 0 3px rgba(24,24,27,.08); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px; background-size: 5px 5px; background-repeat: no-repeat; }
.search { position: relative; }
.search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search .input { padding-left: 34px; width: 300px; }
.label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; margin: 0 0 10px; }
.label .help { color: var(--text-3); font-size: 14px; cursor: help; }
.label .right { margin-left: auto; display: flex; gap: 4px; font-weight: 400; }
.field { margin-bottom: 26px; }
.hint { font-size: 12px; margin-top: 6px; color: var(--text-3); min-height: 16px; }
.hint.ok { color: var(--ok); }
.hint.bad { color: var(--bad); }
.form-error { color: var(--bad); font-size: 13px; min-height: 18px; margin: 8px 0; }

.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: 22px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--text); }
.switch input:checked + span::before { transform: translateX(16px); }

/* short link input group (like screenshot) */
.group { display: flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--bg); }
.group:focus-within { border-color: var(--text); box-shadow: 0 0 0 3px rgba(24,24,27,.08); }
.group .domain { display: flex; align-items: center; gap: 8px; padding: 0 14px; min-width: 200px; border-right: 1px solid var(--line); background: var(--bg-soft); color: var(--text-2); font-weight: 500; }
.group .input { border: 0; border-radius: 0; box-shadow: none !important; }

/* tag input */
.tags-input { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 42px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 5px 10px; background: var(--bg); position: relative; cursor: text; }
.tags-input:focus-within { border-color: var(--text); box-shadow: 0 0 0 3px rgba(24,24,27,.08); }
.tags-input > i { color: var(--text-3); }
.tags-input input { border: 0; outline: 0; flex: 1; min-width: 120px; font: inherit; height: 30px; background: transparent; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 500; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.chip button { border: 0; background: none; padding: 0; cursor: pointer; color: inherit; opacity: .7; }
.chip.c1 { background: #fef3c7; color: #92400e; } .chip.c2 { background: #dcfce7; color: #166534; }
.chip.c3 { background: #fce7f3; color: #9d174d; } .chip.c4 { background: #e0f2fe; color: #075985; }
.chip.c5 { background: #f3e8ff; color: #6b21a8; } .chip.c6 { background: #ffedd5; color: #9a3412; }
.suggest { position: absolute; left: -1px; right: -1px; top: calc(100% + 4px); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); z-index: 20; max-height: 220px; overflow: auto; padding: 4px; }
.suggest div { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; }
.suggest div:hover, .suggest div.on { background: var(--bg-muted); }

/* cards */
.card { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.card-pad { padding: 18px 20px; }
.card h3 { font-size: 14px; margin: 0 0 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h3 .right { margin-left: auto; font-weight: 400; }

/* editor page */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 28px; align-items: start; }
.editor-main { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 26px 26px 10px; }
.editor-side { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 14px; padding: 22px; position: sticky; top: 20px; }
.editor-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 0 6px; border-top: 1px solid var(--line); margin-top: 6px; }
.draft { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 14px; }
.dotted { background-color: var(--bg); background-image: radial-gradient(var(--line-strong) 1px, transparent 1px); background-size: 6px 6px; border: 1px solid var(--line); border-radius: 10px; }
.qr-box { height: 170px; display: grid; place-items: center; position: relative; }
.qr-box canvas, .qr-box img { background: #fff; padding: 8px; border-radius: 6px; }
.qr-box .qr-actions { position: absolute; right: 8px; top: 8px; display: flex; gap: 4px; }
.qr-box .qr-actions .icon-btn { background: var(--bg); border: 1px solid var(--line); }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.tabs button { height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); cursor: pointer; font-size: 16px; color: var(--text-2); }
.tabs button.on { border-color: var(--text); color: var(--text); box-shadow: 0 0 0 1px var(--text) inset; }
.og { overflow: hidden; }
.og .og-img { height: 190px; display: grid; place-items: center; color: var(--text-2); text-align: center; font-size: 14px; position: relative; background-size: cover; background-position: center; }
.og .og-img i { font-size: 22px; display: block; margin-bottom: 8px; }
.og-fields { padding-top: 12px; }
.og-fields input, .og-fields textarea { width: 100%; border: 0; background: transparent; font: inherit; outline: 0; padding: 4px 0; resize: none; color: var(--text); }
.og-fields input { font-weight: 600; font-size: 15px; }
.og-fields textarea { color: var(--text-2); min-height: 40px; }
.og.x .og-img { border-radius: 14px; } .og.x .og-meta { font-size: 12px; color: var(--text-3); padding: 6px 2px 0; }
.og.fb .og-meta, .og.li .og-meta { font-size: 11px; text-transform: uppercase; color: var(--text-3); padding: 8px 2px 0; }
.og.fb .og-img, .og.li .og-img { border-radius: 4px; }
.preview-toggle { display: flex; align-items: center; gap: 10px; margin-left: auto; }

/* link list */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .select { width: auto; min-width: 140px; height: 36px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto auto; gap: 14px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; transition: border-color .12s, box-shadow .12s; }
.row:hover { border-color: var(--line-strong); box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.row .fav { width: 36px; height: 36px; border-radius: 50%; background: var(--bg-muted); display: grid; place-items: center; color: var(--text-2); }
.row .l1 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row .short { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .l2 { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; margin-top: 3px; min-width: 0; }
.row .l2 .dest { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .l2 .when { white-space: nowrap; color: var(--text-3); }
.row .tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 260px; }
.clicks-pill { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 8px; background: var(--bg-muted); font-size: 13px; font-weight: 500; cursor: pointer; border: 0; white-space: nowrap; }
.clicks-pill:hover { background: var(--line); }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: 36px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; z-index: 30; min-width: 170px; }
.menu-pop button { display: flex; width: 100%; align-items: center; gap: 10px; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; text-align: left; }
.menu-pop button:hover { background: var(--bg-muted); }
.menu-pop button i { width: 16px; color: var(--text-3); text-align: center; }
.menu-pop .danger, .menu-pop .danger i { color: var(--bad); }
.empty { text-align: center; padding: 60px 20px; color: var(--text-2); background: var(--bg); border: 1px dashed var(--line-strong); border-radius: 12px; }
.empty i { font-size: 28px; color: var(--text-3); margin-bottom: 10px; display: block; }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.pager .info { color: var(--text-2); flex: 1; }
.pager .pages { display: flex; gap: 4px; }
.pager .pages button { min-width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
.pager .pages button.on { background: var(--text); color: #fff; border-color: var(--text); }
.pager .pages button:disabled { opacity: .4; cursor: default; }
.pager .pages .gap { padding: 0 4px; color: var(--text-3); align-self: center; }
.pager .select { width: auto; height: 34px; }

/* analytics */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.kpi .k { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kpi .v img.flag { width: 28px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-top: 16px; }
.chart { width: 100%; height: 220px; display: block; }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart .axis { fill: var(--text-3); font-size: 11px; }
.chart .gridline { stroke: var(--line); }
.map-wrap { position: relative; }
.map-wrap svg.world { width: 100%; height: auto; display: block; }
.map-wrap svg.world path { fill: #e4e4e7; stroke: #fff; stroke-width: .4; transition: fill .1s linear; cursor: default; }
.map-wrap svg.world path:hover { fill: #565656 !important; }
.legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); margin-top: 8px; }
.legend .ramp { height: 8px; width: 140px; border-radius: 4px; background: linear-gradient(90deg, #e0e7ff, #4f46e5); }
.bars { display: flex; flex-direction: column; gap: 4px; }
.bars .b { position: relative; display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px; overflow: hidden; }
.bars .b .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent-soft); z-index: 0; border-radius: 6px; }
.bars .b > *:not(.fill) { position: relative; z-index: 1; }
.bars .b .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; }
.bars .b .n { font-weight: 600; font-variant-numeric: tabular-nums; }
.bars .b .pct { color: var(--text-3); font-size: 12px; width: 42px; text-align: right; }
.flag { width: 22px; height: auto; aspect-ratio: 4/3; object-fit: cover; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,.08); flex: none; }
.flag-fallback { width: 22px; text-align: center; color: var(--text-3); flex: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg); }
.seg button { border: 0; background: none; height: 34px; padding: 0 12px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--text); color: #fff; }
.link-filter { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 6px 0 12px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }

/* tooltip / toast / modal */
.tip { position: fixed; pointer-events: none; z-index: 100; background: var(--text); color: #fff; padding: 8px 10px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .08s; display: flex; align-items: center; gap: 8px; white-space: nowrap; box-shadow: var(--shadow); }
.tip.on { opacity: 1; }
.tip .flag { box-shadow: none; }
.tip b { font-weight: 600; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; z-index: 200; pointer-events: none; display: flex; gap: 8px; align-items: center; }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); }
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 150; padding: 20px; }
.modal { background: var(--bg); border-radius: 14px; padding: 22px; width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 30px; box-shadow: var(--shadow); text-align: left; }
.login-card .muted { text-align: center; margin: 4px 0 22px; }
.login-card .input { margin-bottom: 4px; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .editor-side { position: static; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .sidebar .nav { flex-direction: row; }
  .nav-section, #folderNav { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; }
  .main { padding: 18px 14px 50px; }
  .search .input { width: 100%; }
  .search { flex: 1; }
  .row { grid-template-columns: 36px minmax(0, 1fr) auto auto; gap: 8px; padding: 10px; }
  .clicks-pill { padding: 0 8px; }
  .toolbar .search { flex-basis: 100%; }
  .toolbar .select { flex: 1; min-width: 0; }
  .seg { overflow-x: auto; max-width: 100%; }
  .row .tags { display: none; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .group .domain { min-width: 0; }
}
