/* LinkLite — theme colors come from CSS variables injected per-site:
   --primary and --accent are set inline in <head> from admin settings. */
:root {
  --primary: #6366f1;
  --accent: #22c55e;
  --bg: #f1f3f9;
  --card: #ffffff;
  --text: #1e2235;
  --muted: #6b7280;
  --border: #e5e7ef;
  --danger: #ef4444;
  --radius: 14px;
  --sidebar-w: 248px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- shell */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: color-mix(in srgb, var(--primary) 14%, #14172b);
  color: #e7e9f5;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 20px;
  color: #fff; text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: .2px; }
.brand-logo { height: 34px; max-width: 150px; object-fit: contain; }
.brand-logo-lg { height: 48px; max-width: 200px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 55%, var(--accent)));
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 18px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 45%, transparent);
}
.brand-mark-lg { width: 56px; height: 56px; font-size: 28px; border-radius: 16px; }

.nav { flex: 1; padding: 8px 12px; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin: 2px 0;
  border-radius: 10px;
  color: #b9bed6; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav a.active { background: var(--primary); color: #fff; box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 40%, transparent); }
.nav svg { width: 19px; height: 19px; fill: currentColor; flex-shrink: 0; }
.nav-section {
  margin: 18px 12px 6px; font-size: 11px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: #7c81a0;
}

.sidebar-footer {
  display: flex; align-items: center; gap: 6px;
  padding: 14px 12px; border-top: 1px solid rgba(255, 255, 255, .08);
}
.user-chip {
  flex: 1; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; color: #e7e9f5;
}
.user-chip:hover, .user-chip.active { background: rgba(255, 255, 255, .08); text-decoration: none; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-meta strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: #8e93b3; font-size: 11.5px; text-transform: capitalize; }
.logout-btn { padding: 8px; border-radius: 8px; color: #8e93b3; display: inline-flex; }
.logout-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.logout-btn svg { width: 18px; height: 18px; fill: currentColor; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 28px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 22px 0 6px; }
.topbar h1 { font-size: 22px; margin: 0; font-weight: 700; }
.content { flex: 1; display: flex; flex-direction: column; gap: 18px; padding: 12px 0 24px; }
.footer { padding: 16px 0 22px; color: var(--muted); font-size: 13px; text-align: center; border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.card-title { margin: 0 0 14px; font-size: 15px; font-weight: 700; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head .card-title { margin: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 30px; font-weight: 800; color: var(--text); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.four-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; align-items: start; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- tables */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.table td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; }
.truncate { max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions-col { width: 1%; white-space: nowrap; }
.actions { white-space: nowrap; text-align: right; }
.muted { color: var(--muted); font-size: 12.5px; }
.link-title { color: var(--muted); font-size: 12.5px; }
.short-link { font-weight: 600; }
.short-link-lg { font-size: 19px; font-weight: 700; }
.link-dest { color: var(--muted); margin-top: 4px; max-width: 640px; }
.link-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.link-header-meta { display: flex; gap: 8px; flex-shrink: 0; }

.copy-btn {
  border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: 14px; padding: 2px 6px; border-radius: 6px;
}
.copy-btn:hover { background: var(--bg); color: var(--primary); }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700;
}
.badge-ok      { background: color-mix(in srgb, var(--accent) 15%, #fff); color: color-mix(in srgb, var(--accent) 80%, #000); }
.badge-off     { background: #eceef4; color: #6b7280; }
.badge-warn    { background: #fef3c7; color: #92400e; }
.badge-primary { background: color-mix(in srgb, var(--primary) 14%, #fff); color: var(--primary); }
.badge-neutral { background: #eceef4; color: #4b5563; }

/* ---------------------------------------------------------------- forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; flex: 1; }
.form label small { color: var(--muted); font-weight: 400; }
.form input[type=text], .form input[type=url], .form input[type=email],
.form input[type=password], .form input[type=number], .form input[type=search],
.form input[type=datetime-local], .form select, .search-form input[type=search] {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font: inherit; background: #fbfcfe; color: var(--text); width: 100%;
}
.form input:focus, .form select:focus, .search-form input:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent);
  border-color: var(--primary);
}
.form-row { display: flex; gap: 14px; }
.form-section { margin: 10px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.form-actions { display: flex; gap: 10px; }
.form-inline { flex-direction: row; align-items: center; flex-wrap: wrap; }
.form-inline input, .form-inline select { width: auto; flex: 1; min-width: 140px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font: inherit; background: #fbfcfe; }
.checkbox { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 500 !important; white-space: nowrap; }
.checkbox input { width: auto !important; }
.search-form { display: flex; gap: 10px; margin-bottom: 14px; }
.search-form input { flex: 1; }
.hint { color: var(--muted); margin: -6px 0 14px; font-size: 13px; }
.inline { display: inline; }
.settings-card { max-width: 720px; }
.logo-row { align-items: center; }
.logo-preview { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.logo-preview img { max-height: 48px; max-width: 180px; background: #14172b; padding: 6px 10px; border-radius: 8px; }
.color-input { display: flex; align-items: center; gap: 10px; }
.color-input input[type=color] { width: 46px; height: 34px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: #fff; cursor: pointer; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; text-decoration: none !important; transition: all .15s;
}
.btn-primary {
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 35%, transparent);
}
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 85%, #000); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 8%, #fff); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------- flash */
.flash { padding: 12px 16px; border-radius: 10px; font-weight: 500; margin-bottom: 4px; }
.flash-success { background: color-mix(in srgb, var(--accent) 12%, #fff); color: color-mix(in srgb, var(--accent) 70%, #000); border: 1px solid color-mix(in srgb, var(--accent) 30%, #fff); }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; min-height: 220px; }
.chart svg { display: block; width: 100%; height: 240px; }
.chart-tip {
  position: fixed; pointer-events: none; z-index: 50;
  background: #14172b; color: #fff; font-size: 12px;
  padding: 6px 10px; border-radius: 8px; transform: translate(-50%, -130%);
  white-space: nowrap; opacity: 0; transition: opacity .1s;
}

.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 38%) 1fr 44px; gap: 10px; align-items: center; }
.bar-label { font-size: 13px; font-weight: 500; }
.bar-track { background: var(--bg); border-radius: 999px; height: 8px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), color-mix(in srgb, var(--primary) 55%, var(--accent))); }
.bar-value { text-align: right; font-weight: 700; font-size: 13px; }

.range-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 9px; padding: 3px; }
.range-tab { padding: 4px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.range-tab:hover { text-decoration: none; color: var(--text); }
.range-tab.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }

.pagination { display: flex; gap: 6px; margin-top: 14px; }
.page-btn { padding: 5px 11px; border-radius: 8px; border: 1px solid var(--border); font-weight: 600; font-size: 13px; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:hover { text-decoration: none; }

.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* ---------------------------------------------------------------- auth */
.auth-body { background: linear-gradient(160deg, color-mix(in srgb, var(--primary) 10%, var(--bg)), var(--bg) 55%); min-height: 100vh; display: flex; }
.auth-wrap { margin: auto; width: 100%; max-width: 440px; padding: 40px 20px; display: flex; flex-direction: column; gap: 22px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.auth-brand h1 { margin: 0; font-size: 24px; }
.auth-card h2 { margin: 0 0 18px; font-size: 17px; }
.auth-alt { text-align: center; color: var(--muted); margin: 16px 0 0; }
.auth-footer { text-align: center; color: var(--muted); font-size: 13px; margin: 0; }
.error-card { text-align: center; }
.error-code { font-size: 64px; font-weight: 800; color: var(--primary); line-height: 1; margin-bottom: 8px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .nav { display: flex; padding: 0 8px 8px; }
  .nav-section { display: none; }
  .sidebar-footer { border-top: none; margin-left: auto; }
  .main { padding: 0 16px; }
  .truncate { max-width: 160px; }
}
