/* ==========================================================================
   link.az – design system
   Light theme, Material / Tailwind-style tokens and utilities.
   Sections: 1 tokens · 2 base · 3 components · 4 layouts · 5 pages · 6 utilities
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
    --primary: #3F51B5;        /* indigo 500 */
    --primary-hover: #3546A0;
    --primary-soft: #E8EAF6;   /* indigo 50 */
    --accent: #FF7043;         /* deep orange – used once, for the featured link */
    --success: #2E7D32; --success-soft: #E8F5E9;
    --danger: #C62828;  --danger-soft: #FFEBEE;
    --warning: #EF6C00; --warning-soft: #FFF3E0;

    --bg: #F5F7FA;             /* page */
    --surface: #FFFFFF;        /* cards */
    --surface-2: #F1F3F8;      /* muted rows */
    --border: #E3E7EE;
    --ink: #1F2937;            /* primary text */
    --ink-2: #4B5563;          /* secondary text */
    --muted: #6B7280;
    --muted-2: #9CA3AF;

    --radius-sm: 6px; --radius: 10px; --radius-lg: 16px; --radius-full: 999px;
    --shadow-1: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --shadow-2: 0 4px 12px rgba(16, 24, 40, .10);
    --shadow-3: 0 12px 32px rgba(16, 24, 40, .14);

    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --fs-xs: .75rem; --fs-sm: .875rem; --fs-base: 1rem; --fs-lg: 1.125rem;
    --fs-xl: 1.25rem; --fs-2xl: 1.5rem; --fs-3xl: 1.875rem; --fs-4xl: 2.5rem;

    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;
    --sidebar-w: 240px;
    --ease: 160ms cubic-bezier(.2, 0, 0, 1);
}

/* 2. Base ------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--ink);
    font: 400 var(--fs-base)/1.55 var(--font);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 var(--sp-2); font-weight: 600; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: var(--fs-3xl); } h2 { font-size: var(--fs-2xl); } h3 { font-size: var(--fs-xl); } h4 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
table { border-collapse: collapse; width: 100%; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* 3. Components ------------------------------------------------------------- */

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    min-height: 40px; padding: 0 var(--sp-4); border-radius: var(--radius-sm); border: 1px solid transparent;
    font-weight: 500; font-size: var(--fs-sm); line-height: 1; cursor: pointer; white-space: nowrap;
    background: var(--surface-2); color: var(--ink); transition: background var(--ease), box-shadow var(--ease), border-color var(--ease);
    text-decoration: none;
}
.btn:hover { background: #E7EAF1; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { min-height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.btn-lg { min-height: 48px; padding: 0 var(--sp-6); font-size: var(--fs-base); }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 36px; min-height: 36px; border-radius: var(--radius-full); }
.btn svg { width: 18px; height: 18px; flex: none; }

/* Forms */
.field { margin-bottom: var(--sp-4); }
.label { display: block; font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); margin-bottom: var(--sp-1); }
.input, .select, .textarea {
    width: 100%; min-height: 42px; padding: var(--sp-2) var(--sp-3); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm); transition: border-color var(--ease), box-shadow var(--ease);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { min-height: 140px; resize: vertical; line-height: 1.55; }
.select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236B7280' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.hint { font-size: var(--fs-xs); color: var(--muted); margin-top: var(--sp-1); }
.input-group { display: flex; }
.input-group .prefix { display: flex; align-items: center; padding: 0 var(--sp-3); background: var(--surface-2); border: 1px solid var(--border); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }
.input-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.checkbox { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); cursor: pointer; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--primary); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-1); }
.card-body { padding: var(--sp-5); }
.card-header { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.card-header h3 { margin: 0; font-size: var(--fs-base); }
@media (min-width: 640px) { .card-body { padding: var(--sp-6); } }

/* Alerts */
.alert { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm); font-size: var(--fs-sm); margin-bottom: var(--sp-3); border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: #C8E6C9; }
.alert-error   { background: var(--danger-soft);  color: var(--danger);  border-color: #FFCDD2; }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: #FFE0B2; }
.alert-info    { background: var(--primary-soft); color: var(--primary); border-color: #C5CAE9; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: var(--radius-full); font-size: var(--fs-xs); font-weight: 500; background: var(--surface-2); color: var(--ink-2); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table th, .table td { padding: var(--sp-3) var(--sp-4); text-align: left; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: var(--fs-xs); background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .bar { position: relative; }
.table .bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--primary-soft); z-index: 0; border-radius: 2px; }
.table .bar-label { position: relative; z-index: 1; }

/* Avatar */
.avatar { width: 40px; height: 40px; border-radius: var(--radius-full); object-fit: cover; background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; flex: none; overflow: hidden; }
.avatar-lg { width: 96px; height: 96px; font-size: var(--fs-3xl); }
.avatar-sm { width: 32px; height: 32px; font-size: var(--fs-sm); }

/* Stat card */
.stat { padding: var(--sp-4) var(--sp-5); }
.stat .stat-label { font-size: var(--fs-sm); color: var(--muted); }
.stat .stat-value { font-size: var(--fs-3xl); font-weight: 600; letter-spacing: -.02em; line-height: 1.1; margin: var(--sp-1) 0; font-variant-numeric: tabular-nums; }
.stat .stat-hint { font-size: var(--fs-xs); color: var(--muted-2); }

/* Segmented control (analytics range) */
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: var(--radius-sm); }
.segmented button { border: 0; background: transparent; padding: 6px 12px; border-radius: 4px; font-size: var(--fs-sm); color: var(--ink-2); cursor: pointer; }
.segmented button.is-active { background: var(--surface); color: var(--primary); font-weight: 500; box-shadow: var(--shadow-1); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; padding: var(--sp-4); background: rgba(17, 24, 39, .45); }
.modal.is-open { display: flex; }
.modal-panel { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-3); }
.modal-panel .card-body { padding: var(--sp-6); }

/* Empty state */
.empty { text-align: center; padding: var(--sp-10) var(--sp-4); color: var(--muted); }
.empty svg { width: 48px; height: 48px; margin: 0 auto var(--sp-3); color: var(--muted-2); }

/* Toast / flash stack */
.flashes { position: fixed; top: var(--sp-4); right: var(--sp-4); left: var(--sp-4); z-index: 60; display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none; }
.flashes .alert { pointer-events: auto; box-shadow: var(--shadow-2); margin: 0; }
@media (min-width: 640px) { .flashes { left: auto; width: 380px; } }

/* 4. Layouts ---------------------------------------------------------------- */

/* Top bar (marketing + auth) */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 0 var(--sp-4); height: 60px; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.brand { font-weight: 700; font-size: var(--fs-lg); color: var(--ink); letter-spacing: -.02em; display: inline-flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.container { max-width: 1080px; margin: 0 auto; padding: var(--sp-6) var(--sp-4); }
.container-sm { max-width: 720px; }

/* Language picker */
.lang-switch { display: inline-flex; gap: 2px; }
.lang-switch a { padding: 4px 8px; border-radius: 4px; font-size: var(--fs-xs); font-weight: 500; color: var(--muted); text-transform: uppercase; }
.lang-switch a.is-active { background: var(--primary-soft); color: var(--primary); }
.lang-switch a:hover { text-decoration: none; background: var(--surface-2); }

/* Auth pages */
.auth-wrap { min-height: calc(100vh - 60px); display: flex; align-items: flex-start; justify-content: center; padding: var(--sp-8) var(--sp-4); }
.auth-card { width: 100%; max-width: 420px; }
.divider { display: flex; align-items: center; gap: var(--sp-3); color: var(--muted-2); font-size: var(--fs-xs); margin: var(--sp-4) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Dashboard shell: sidebar on desktop, bottom tabs on mobile */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    display: none; width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--border);
    padding: var(--sp-4); position: sticky; top: 0; height: 100vh; flex-direction: column; gap: var(--sp-2);
}
.sidebar .brand { padding: var(--sp-2) var(--sp-3) var(--sp-4); }
.nav-item { display: flex; align-items: center; gap: var(--sp-3); padding: 10px var(--sp-3); border-radius: var(--radius-sm); color: var(--ink-2); font-size: var(--fs-sm); font-weight: 500; }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary); }
.nav-item svg { width: 20px; height: 20px; flex: none; }
.sidebar-footer { margin-top: auto; padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.main { flex: 1; min-width: 0; padding: var(--sp-4) var(--sp-4) 88px; }
.main-inner { max-width: 960px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head h1 { font-size: var(--fs-2xl); margin: 0; }
.mobile-bar { display: flex; position: sticky; top: 0; z-index: 20; align-items: center; justify-content: space-between; background: var(--surface); border-bottom: 1px solid var(--border); padding: var(--sp-2) var(--sp-4); margin: calc(-1 * var(--sp-4)) calc(-1 * var(--sp-4)) var(--sp-4); }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; font-size: 11px; color: var(--muted); }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.is-active { color: var(--primary); }
.tabbar a:hover { text-decoration: none; }
@media (min-width: 900px) {
    .sidebar { display: flex; }
    .main { padding: var(--sp-8) var(--sp-8); }
    .mobile-bar, .tabbar { display: none; }
}

/* Admin shell is desktop-only by requirement, but still degrades gracefully */
.shell-admin .sidebar { display: flex; }
.shell-admin .main { padding: var(--sp-8); }
.shell-admin .main-inner { max-width: 1200px; }
.shell-admin .mobile-bar, .shell-admin .tabbar { display: none; }

/* 5. Pages ------------------------------------------------------------------ */

/* Landing */
.hero { padding: var(--sp-12) 0 var(--sp-8); text-align: center; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.25rem); letter-spacing: -.03em; max-width: 16ch; margin: 0 auto var(--sp-4); }
.hero p { max-width: 56ch; margin: 0 auto var(--sp-6); color: var(--ink-2); font-size: var(--fs-lg); }
.hero-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-3); }
.hero-url { display: inline-flex; align-items: center; margin-bottom: var(--sp-5); padding: 6px 14px; border-radius: var(--radius-full); background: var(--primary-soft); color: var(--primary); font-weight: 500; font-size: var(--fs-sm); }
.features { display: grid; gap: var(--sp-4); margin-top: var(--sp-8); }
.feature h3 { font-size: var(--fs-lg); }
.feature p { color: var(--ink-2); font-size: var(--fs-sm); margin: 0; }
@media (min-width: 720px) { .features { grid-template-columns: repeat(3, 1fr); } }

/* Public profile */
.profile-page { max-width: 560px; margin: 0 auto; padding: var(--sp-10) var(--sp-4) var(--sp-8); }
.profile-head { text-align: center; margin-bottom: var(--sp-6); }
.profile-head .avatar { margin: 0 auto var(--sp-3); }
.profile-head h1 { font-size: var(--fs-2xl); margin-bottom: 2px; }
.profile-head .handle { color: var(--muted); font-size: var(--fs-sm); }
.links-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.link-btn {
    display: flex; align-items: center; justify-content: center; text-align: center; min-height: 56px; padding: var(--sp-3) var(--sp-5);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--ink); font-weight: 500;
    box-shadow: var(--shadow-1); transition: transform var(--ease), box-shadow var(--ease), border-color var(--ease);
}
.link-btn:hover { text-decoration: none; border-color: var(--primary); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.link-featured {
    display: block; padding: var(--sp-5); background: var(--surface); border: 2px solid var(--primary); border-radius: var(--radius-lg);
    color: var(--ink); box-shadow: var(--shadow-2); margin-bottom: var(--sp-2);
}
.link-featured:hover { text-decoration: none; box-shadow: var(--shadow-3); }
.link-featured .title { font-size: var(--fs-xl); font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.link-featured .title::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.link-featured .desc { color: var(--ink-2); font-size: var(--fs-sm); }
.link-featured .host { color: var(--muted-2); font-size: var(--fs-xs); margin-top: var(--sp-2); }
.profile-about { margin-top: var(--sp-8); padding-top: var(--sp-6); border-top: 1px solid var(--border); }
.profile-about h2 { font-size: var(--fs-lg); }
.profile-about p { color: var(--ink-2); white-space: pre-line; }
.profile-foot { text-align: center; margin-top: var(--sp-8); font-size: var(--fs-xs); color: var(--muted-2); }

/* Dashboard link list */
.link-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); background: var(--surface); }
.link-row:last-child { border-bottom: 0; }
.link-row.is-hidden { opacity: .55; }
.link-row.is-dragging { opacity: .4; }
.link-row.is-over { box-shadow: inset 0 3px 0 var(--primary); }
.link-row .grip { cursor: grab; color: var(--muted-2); touch-action: none; padding: 4px; }
.link-row .grip svg { width: 18px; height: 18px; }
.link-row .info { flex: 1; min-width: 0; }
.link-row .info .t { font-weight: 500; display: flex; align-items: center; gap: 8px; }
.link-row .info .u { font-size: var(--fs-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row .clicks { font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; }
.link-row .acts { display: flex; gap: 2px; }
@media (max-width: 640px) { .link-row .clicks { display: none; } }

/* Analytics */
.analytics-toolbar { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; margin-bottom: var(--sp-5); }
.custom-range { display: none; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.custom-range.is-open { display: flex; }
.custom-range input { min-height: 36px; }
.stats-grid { display: grid; gap: var(--sp-3); grid-template-columns: repeat(2, 1fr); margin-bottom: var(--sp-5); }
@media (min-width: 900px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.chart-card { margin-bottom: var(--sp-5); }
.chart { width: 100%; height: 260px; display: block; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .line-views { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; }
.chart .line-clicks { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .area-views { fill: var(--primary); opacity: .08; }
.chart .dot { fill: var(--surface); stroke-width: 2; }
.chart-legend { display: flex; gap: var(--sp-4); font-size: var(--fs-xs); color: var(--muted); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: var(--fs-xs); padding: 6px 10px; border-radius: 6px; transform: translate(-50%, -110%); white-space: nowrap; display: none; }
.breakdown-grid { display: grid; gap: var(--sp-4); }
@media (min-width: 900px) { .breakdown-grid { grid-template-columns: repeat(2, 1fr); } }
.flag { margin-right: 6px; }

/* Settings avatar row */
.avatar-row { display: flex; align-items: center; gap: var(--sp-4); }

/* Error page */
.error-page { text-align: center; padding: var(--sp-12) var(--sp-4); }
.error-page .code { font-size: 5rem; font-weight: 700; color: var(--primary-soft); line-height: 1; }

/* 6. Utilities ------------------------------------------------------------- */
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; } .flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); }
.grid { display: grid; } .grid-2 { grid-template-columns: repeat(2, 1fr); }
.mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); } .mt-6 { margin-top: var(--sp-6); }
.mb-2 { margin-bottom: var(--sp-2); } .mb-3 { margin-bottom: var(--sp-3); } .mb-4 { margin-bottom: var(--sp-4); } .mb-6 { margin-bottom: var(--sp-6); }
.text-sm { font-size: var(--fs-sm); } .text-xs { font-size: var(--fs-xs); } .text-muted { color: var(--muted); } .text-center { text-align: center; }
.font-medium { font-weight: 500; } .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; } .w-full { width: 100%; } .ml-auto { margin-left: auto; }
.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; }
@media (min-width: 640px) { .sm-grid-2 { grid-template-columns: repeat(2, 1fr); } .sm-hidden { display: none !important; } }
@media (max-width: 639px) { .xs-hidden { display: none !important; } .xs-block { display: block !important; width: 100%; } }
