:root {
    --bg: #0b0b0e;
    --surface: #131318;
    --surface-2: #19191f;
    --surface-3: #222229;
    --red: #d42b38;
    --red-dark: #7f111c;
    --red-glow: rgba(212, 43, 56, .22);
    --gold: #d6a84b;
    --text: #f6f2ee;
    --muted: #8e8b92;
    --line: rgba(255, 255, 255, .075);
    --green: #35c879;
    --blue: #5ca8ff;
    --orange: #f09a4a;
    --radius: 18px;
    --shadow: 0 18px 60px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
input, select, textarea {
    width: 100%;
    padding: .78rem .9rem;
    color: var(--text);
    background: #0f0f13;
    border: 1px solid var(--line);
    border-radius: 11px;
    outline: none;
    transition: .2s ease;
}
input:focus, select:focus, textarea:focus {
    border-color: rgba(212, 43, 56, .7);
    box-shadow: 0 0 0 3px rgba(212, 43, 56, .1);
}
input[type="checkbox"] { width: auto; accent-color: var(--red); }
label { display: grid; gap: .45rem; color: #c8c5ca; font-size: .84rem; font-weight: 600; }
.muted { color: var(--muted); }
.overline {
    margin-bottom: .55rem;
    color: var(--red);
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .16em;
}
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .55rem;
    min-height: 42px;
    padding: .65rem 1rem;
    border: 1px solid transparent;
    border-radius: 11px;
    cursor: pointer;
    font-weight: 700;
    transition: transform .15s, background .2s, border-color .2s;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
    color: white;
    background: linear-gradient(135deg, #e03543, #a81524);
    box-shadow: 0 8px 24px rgba(212, 43, 56, .22);
}
.btn-secondary { color: var(--text); background: var(--surface-2); border-color: var(--line); }
.btn-block { width: 100%; }
.btn-link {
    padding: 0;
    color: #e96b75;
    background: transparent;
    border: 0;
    cursor: pointer;
    font-weight: 700;
}
.icon-button {
    width: 39px;
    height: 39px;
    color: var(--muted);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
}
.icon-button.danger:hover { color: #ff6d78; border-color: rgba(212, 43, 56, .5); }
.alert { padding: .8rem 1rem; border-radius: 10px; }
.alert-error { color: #ffb4ba; background: rgba(212, 43, 56, .13); border: 1px solid rgba(212, 43, 56, .3); }

/* Login */
.login-page {
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 2rem;
    background:
        radial-gradient(circle at 12% 20%, rgba(212,43,56,.18), transparent 34%),
        radial-gradient(circle at 90% 90%, rgba(127,17,28,.12), transparent 30%),
        #08080a;
}
.login-page::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .22;
    background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
    background-size: 46px 46px;
}
.login-shell {
    z-index: 1;
    display: grid;
    grid-template-columns: minmax(300px, 1fr) minmax(340px, 420px);
    width: min(960px, 100%);
    overflow: hidden;
    background: rgba(15, 15, 19, .9);
    border: 1px solid var(--line);
    border-radius: 26px;
    box-shadow: 0 35px 120px rgba(0,0,0,.55);
    backdrop-filter: blur(18px);
}
.login-brand {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 570px;
    padding: 4rem;
    background: linear-gradient(150deg, rgba(212,43,56,.13), transparent 58%);
    border-right: 1px solid var(--line);
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin-bottom: 2rem;
    color: white;
    background: linear-gradient(145deg, #ea3a48, #8c121f);
    border-radius: 18px;
    box-shadow: 0 14px 35px rgba(212,43,56,.25);
    font-family: Georgia, serif;
    font-size: 1.35rem;
    font-weight: 700;
}
.brand-mark.small { width: 42px; height: 42px; margin: 0; border-radius: 12px; font-size: .9rem; }
.login-brand h1 { max-width: 500px; margin-bottom: 1rem; font-size: clamp(2.2rem, 5vw, 4.4rem); line-height: .98; font-family: Georgia, serif; font-weight: 500; }
.login-brand > p:not(.overline) { max-width: 480px; color: var(--muted); font-size: 1.05rem; line-height: 1.7; }
.security-chip { display: inline-flex; align-items: center; gap: .55rem; margin-top: 2rem; color: #bbb7bc; font-size: .78rem; }
.security-chip span, .live-dot { width: 8px; height: 8px; background: var(--green); border-radius: 50%; box-shadow: 0 0 0 4px rgba(53,200,121,.1); }
.login-card { display: flex; flex-direction: column; justify-content: center; gap: 1rem; padding: 3.5rem; }
.login-card h2 { margin-bottom: 0; font-size: 2rem; }
.login-card .muted { margin-bottom: .5rem; }

/* Shell */
.admin-page { display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 1.25rem 1rem;
    background: #0e0e12;
    border-right: 1px solid var(--line);
    z-index: 20;
}
.sidebar-brand { display: flex; align-items: center; gap: .8rem; padding: 0 .3rem 1.4rem; border-bottom: 1px solid var(--line); }
.sidebar-brand div:last-child { display: grid; gap: .1rem; }
.sidebar-brand strong { font-family: Georgia, serif; font-size: 1.05rem; }
.sidebar-brand span { color: var(--muted); font-size: .65rem; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-nav { display: grid; gap: .3rem; margin-top: 1.3rem; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .78rem .85rem;
    color: #aaa7ad;
    border-radius: 11px;
    font-weight: 650;
    transition: .2s;
}
.sidebar-nav a:hover, .sidebar-nav a.active { color: white; background: rgba(212,43,56,.12); }
.sidebar-nav a.active { box-shadow: inset 3px 0 var(--red); }
.nav-icon { display: grid; place-items: center; width: 22px; color: #de5360; font-size: 1.05rem; }
.nav-badge { margin-left: auto; padding: .12rem .42rem; color: white; background: var(--red); border-radius: 20px; font-size: .65rem; }
.sidebar-bottom { display: grid; gap: .6rem; margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--line); }
.site-link, .logout-button { display: block; width: 100%; padding: .65rem .8rem; color: var(--muted); background: transparent; border: 0; cursor: pointer; text-align: left; }
.site-link:hover, .logout-button:hover { color: white; }
.admin-main { min-width: 0; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 70px;
    padding: .75rem 2rem;
    background: rgba(11,11,14,.82);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px);
}
.topbar-title { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .78rem; }
.admin-profile { display: flex; align-items: center; gap: .7rem; }
.admin-profile > div:first-child { display: grid; justify-items: end; }
.admin-profile span { color: var(--muted); font-size: .7rem; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; background: linear-gradient(135deg, var(--red), var(--red-dark)); border-radius: 50%; font-weight: 800; }
.mobile-menu { display: none; color: white; background: transparent; border: 0; font-size: 1.2rem; }
.page-content { width: min(1500px, 100%); margin: auto; padding: 2.1rem; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.6rem; }
.page-heading h1 { margin-bottom: .3rem; font-size: clamp(1.9rem, 4vw, 3rem); font-family: Georgia, serif; font-weight: 500; }
.page-heading p:not(.overline) { margin-bottom: 0; color: var(--muted); }
.heading-actions { display: flex; align-items: center; gap: .6rem; }
.period-tabs { display: flex; padding: .25rem; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; }
.period-tabs a { padding: .55rem .8rem; color: var(--muted); border-radius: 8px; font-size: .78rem; font-weight: 700; }
.period-tabs a.active { color: white; background: var(--red); }

/* Dashboard */
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: .85rem; margin-bottom: .9rem; }
.metric-card, .panel {
    background: linear-gradient(145deg, rgba(24,24,30,.98), rgba(17,17,21,.98));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.metric-card { position: relative; overflow: hidden; padding: 1.15rem; }
.metric-card::after { content: ""; position: absolute; width: 80px; height: 80px; right: -35px; top: -35px; background: var(--red-glow); border-radius: 50%; filter: blur(12px); }
.metric-top { display: flex; justify-content: space-between; color: var(--muted); font-size: .75rem; }
.metric-top b { color: #e55864; }
.metric-card > strong { display: block; margin: .85rem 0 .4rem; font-size: 1.85rem; line-height: 1; }
.metric-card small { color: var(--green); font-size: .68rem; }
.metric-card small.down { color: #ff6d78; }
.panel { padding: 1.2rem; margin-bottom: .9rem; }
.panel.no-padding { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.panel-head h2 { margin-bottom: .2rem; font-size: 1rem; }
.panel-head p { margin-bottom: 0; color: var(--muted); font-size: .73rem; }
.chart-panel canvas { width: 100%; max-height: 250px; }
.chart-legend { display: flex; gap: 1rem; color: var(--muted); font-size: .7rem; }
.chart-legend span { display: flex; align-items: center; gap: .35rem; }
.chart-legend i { width: 7px; height: 7px; border-radius: 50%; }
.chart-legend i.red { background: var(--red); }
.chart-legend i.gold { background: var(--gold); }
.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.triple-grid { display: grid; grid-template-columns: 1.35fr 1fr 1fr; gap: .9rem; }
.rank-list { display: grid; }
.rank-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: .6rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.rank-row:last-child { border: 0; }
.rank { display: grid; place-items: center; width: 24px; height: 24px; color: var(--muted); background: var(--surface-3); border-radius: 7px; font-size: .67rem; }
.rank-row div { display: grid; min-width: 0; gap: .18rem; }
.rank-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .78rem; }
.rank-row small { color: var(--muted); font-size: .65rem; }
.rank-row > b { font-size: .78rem; }
.bar-list { display: grid; gap: .85rem; }
.bar-row > div { display: flex; justify-content: space-between; margin-bottom: .35rem; color: #c3c0c5; font-size: .72rem; }
.bar-row i { display: block; height: 6px; overflow: hidden; background: var(--surface-3); border-radius: 10px; }
.bar-row em { display: block; height: 100%; background: linear-gradient(90deg, var(--red-dark), var(--red)); border-radius: inherit; }
.funnel-list { display: grid; gap: .75rem; }
.funnel-row > div { display: flex; justify-content: space-between; margin-bottom: .3rem; color: #c3c0c5; font-size: .7rem; }
.funnel-row i { display: block; width: 100%; height: 8px; overflow: hidden; background: var(--surface-3); border-radius: 10px; }
.funnel-row em { display: block; min-width: 2px; height: 100%; background: linear-gradient(90deg, #7f111c, #e33a48); border-radius: inherit; }
.compact-stats { display: grid; }
.compact-stats > div { display: flex; align-items: center; justify-content: space-between; padding: .62rem 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: .72rem; }
.compact-stats > div:last-child { border: 0; }
.compact-stats b { color: var(--text); }
.donut-layout { display: flex; align-items: center; justify-content: center; gap: 2rem; min-height: 195px; }
.donut-legend { display: grid; gap: .7rem; }
.donut-legend div { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .72rem; }
.donut-legend i { width: 8px; height: 8px; border-radius: 50%; }

/* Tables */
.data-table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: .85rem .9rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table th { color: #77747b; font-size: .66rem; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
.data-table td { color: #c9c6cb; font-size: .76rem; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: rgba(255,255,255,.018); }
.data-table tr.unread { background: rgba(212,43,56,.045); box-shadow: inset 3px 0 var(--red); }
.data-table td small { display: block; margin-top: .22rem; color: var(--muted); font-size: .66rem; }
.accent { color: #ed6974; }
.empty-state { padding: 2rem; color: var(--muted); text-align: center; }
.type-pill, .status-pill, .lead-status, .mail-status { display: inline-flex; padding: .28rem .55rem; border-radius: 30px; font-size: .63rem; font-weight: 750; }
.type-pill { color: #dbbd7a; background: rgba(214,168,75,.1); }
.status-new { color: #ff949c; background: rgba(212,43,56,.13); }
.status-in_progress { color: #ffc17d; background: rgba(240,154,74,.12); }
.status-contacted { color: #87bfff; background: rgba(92,168,255,.12); }
.status-won { color: #73dfa3; background: rgba(53,200,121,.12); }
.status-lost { color: #aaa; background: rgba(255,255,255,.06); }
.mail-sent { color: #73dfa3; background: rgba(53,200,121,.12); }
.mail-failed { color: #ff949c; background: rgba(212,43,56,.13); }
.mail-pending { color: #ffc17d; background: rgba(240,154,74,.12); }

/* Catalog */
.toolbar { display: flex; gap: .65rem; margin-bottom: 1rem; }
.toolbar input { max-width: 360px; }
.toolbar select { max-width: 190px; }
.bulk-actions { display: flex; align-items: center; justify-content: flex-end; gap: .6rem; margin: -.35rem 0 .8rem; color: var(--muted); font-size: .72rem; }
.bulk-actions select { width: auto; min-width: 150px; }
.product-grid { display: grid; grid-template-columns: repeat(3, minmax(240px, 1fr)); gap: 1rem; }
.product-admin-card { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 17px; box-shadow: var(--shadow); }
.product-card-image { position: relative; height: 190px; overflow: hidden; background: #0d0d10; }
.product-card-image img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s; }
.product-admin-card:hover .product-card-image img { transform: scale(1.035); }
.product-card-image .status-pill { position: absolute; top: .7rem; right: .7rem; backdrop-filter: blur(10px); }
.status-pill.active { color: #8de7b3; background: rgba(14,65,38,.8); }
.status-pill.hidden { color: #c2bec4; background: rgba(25,25,30,.85); }
.product-card-body { padding: 1rem; }
.product-card-body > small { color: #db5a65; font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; }
.product-card-body h3 { margin: .45rem 0; font-size: 1.02rem; }
.product-card-body > p { min-height: 38px; margin-bottom: .8rem; color: var(--muted); font-size: .72rem; line-height: 1.5; }
.product-meta { display: flex; gap: .5rem; margin-bottom: .9rem; }
.product-meta span { padding: .3rem .5rem; color: #aaa6ac; background: var(--surface-3); border-radius: 7px; font-size: .63rem; }
.card-actions { display: flex; gap: .45rem; }
.card-actions .btn { flex: 1; }

/* Dialogs */
.admin-dialog {
    width: min(680px, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 0;
    color: var(--text);
    background: #121217;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 20px;
    box-shadow: 0 30px 120px rgba(0,0,0,.7);
}
.admin-dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(5px); }
.dialog-form { display: grid; gap: 1rem; padding: 1.35rem; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: .9rem; }
.dialog-head h2 { margin: 0; }
.dialog-close { width: 36px; height: 36px; color: var(--muted); background: var(--surface-3); border: 0; border-radius: 9px; cursor: pointer; font-size: 1.2rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; padding-top: .5rem; }
.upload-zone { padding: 1rem; background: rgba(255,255,255,.02); border: 1px dashed rgba(255,255,255,.15); border-radius: 12px; cursor: pointer; }
.upload-zone input { padding: 0; background: transparent; border: 0; }
.upload-zone span { color: var(--muted); font-weight: 400; }
.toggle-label { display: flex; align-items: center; gap: .6rem; cursor: pointer; }
.toggle-label input { display: none; }
.toggle-label > span { position: relative; width: 40px; height: 22px; background: #303038; border-radius: 20px; transition: .2s; }
.toggle-label > span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: white; border-radius: 50%; transition: .2s; }
.toggle-label input:checked + span { background: var(--red); }
.toggle-label input:checked + span::after { transform: translateX(18px); }
.lead-dialog { width: min(760px, calc(100vw - 2rem)); }
.lead-detail { padding: 1.35rem; }
.lead-detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .65rem; margin: 1rem 0; }
.detail-box { padding: .75rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.detail-box small { display: block; color: var(--muted); margin-bottom: .25rem; }
.lead-items { margin: 1rem 0; }
.lead-items li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.lead-controls { display: grid; grid-template-columns: 180px 1fr auto; gap: .6rem; margin-top: 1rem; }
.note-list { display: grid; gap: .5rem; margin-top: 1rem; }
.note-item { padding: .65rem; background: var(--surface-2); border-radius: 9px; font-size: .75rem; }
.note-item small { display: block; margin-top: .3rem; color: var(--muted); }
.settings-panel { max-width: 650px; }
.settings-form { display: grid; gap: .85rem; max-width: 460px; }
.system-metrics { grid-template-columns: repeat(4, 1fr); }
.toast-container { position: fixed; z-index: 1000; right: 1.2rem; bottom: 1.2rem; display: grid; gap: .5rem; }
.toast { min-width: 250px; padding: .85rem 1rem; color: white; background: #202028; border: 1px solid var(--line); border-left: 3px solid var(--green); border-radius: 10px; box-shadow: var(--shadow); }
.toast.error { border-left-color: var(--red); }

@media (max-width: 1180px) {
    .metric-grid { grid-template-columns: repeat(3, 1fr); }
    .product-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
    .admin-page { display: block; }
    .sidebar { position: fixed; left: -260px; transition: left .25s; box-shadow: 20px 0 60px rgba(0,0,0,.45); }
    .sidebar.open { left: 0; }
    .mobile-menu { display: block; }
    .page-content { padding: 1.2rem; }
    .topbar { padding: .7rem 1.2rem; }
    .split-grid { grid-template-columns: 1fr; }
    .triple-grid { grid-template-columns: 1fr; }
    .product-grid { grid-template-columns: repeat(2, 1fr); }
    .login-shell { grid-template-columns: 1fr; max-width: 460px; }
    .login-brand { display: none; }
    .login-card { padding: 2.2rem; min-height: 520px; }
}
@media (max-width: 620px) {
    .page-heading { align-items: flex-start; flex-direction: column; }
    .metric-grid, .system-metrics { grid-template-columns: repeat(2, 1fr); }
    .product-grid { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; }
    .toolbar input, .toolbar select { max-width: none; }
    .form-grid, .lead-detail-grid { grid-template-columns: 1fr; }
    .lead-controls { grid-template-columns: 1fr; }
    .period-tabs { width: 100%; }
    .period-tabs a { flex: 1; text-align: center; }
    .heading-actions { width: 100%; }
    .heading-actions .period-tabs { flex: 1; }
    .admin-profile > div:first-child { display: none; }
    .donut-layout { flex-direction: column; }
}
