:root {
    --ink: #172033;
    --ink-2: #222c42;
    --lime: #b6ee47;
    --lime-soft: #efffd2;
    --paper: #f6f7f2;
    --white: #ffffff;
    --muted: #778096;
    --line: #e4e7df;
    --red: #d44e55;
    --green: #16845b;
    --amber: #b66c17;
    --shadow: 0 18px 50px rgba(23, 32, 51, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(30px, 4vw, 44px); line-height: 1.1; letter-spacing: -.045em; }
h2 { margin-bottom: 4px; font-size: 20px; letter-spacing: -.02em; }
.muted { color: var(--muted); }
.eyebrow { margin-bottom: 8px; color: #75803a; font-size: 11px; font-weight: 800; letter-spacing: .15em; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 20px; display: flex; flex-direction: column; color: #e9edf4; background: var(--ink); }
.brand { display: inline-flex; align-items: center; gap: 11px; font-size: 20px; font-weight: 800; letter-spacing: -.03em; }
.brand small { display: block; color: #8e98aa; font-size: 8px; letter-spacing: .16em; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; color: var(--ink); background: var(--lime); font-size: 17px; font-weight: 900; }
.primary-nav { margin-top: 50px; display: grid; gap: 7px; }
.primary-nav a { padding: 11px 13px; display: flex; align-items: center; gap: 12px; border-radius: 10px; color: #aeb6c4; font-weight: 650; }
.primary-nav a span { width: 20px; color: #8790a2; text-align: center; }
.primary-nav a:hover, .primary-nav a.active { color: var(--white); background: rgba(255, 255, 255, .08); }
.primary-nav a.active span { color: var(--lime); }
.sidebar-footer { margin-top: auto; display: grid; gap: 18px; }
.api-state { padding: 14px; display: flex; align-items: center; gap: 10px; border: 1px solid rgba(255,255,255,.08); border-radius: 11px; background: rgba(255,255,255,.04); font-size: 12px; }
.api-state i { width: 8px; height: 8px; border-radius: 99px; background: var(--lime); box-shadow: 0 0 0 4px rgba(182,238,71,.12); }
.api-state small { color: #8994a6; }
.link-button { padding: 0; color: #929bad; border: 0; background: transparent; cursor: pointer; }

.main-content { min-width: 0; padding: 40px clamp(24px, 4vw, 60px) 64px; }
.mobile-header { display: none; }
.page-header { margin-bottom: 30px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.page-header p:last-child { margin-bottom: 0; }
.button { min-height: 42px; padding: 9px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 10px; cursor: pointer; font-weight: 750; transition: transform .15s, box-shadow .15s; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: not-allowed; }
.button.primary { color: var(--ink); background: var(--lime); box-shadow: 0 8px 20px rgba(153, 202, 55, .2); }
.button.subtle { color: #485269; border-color: var(--line); background: var(--white); }
.button.danger { color: var(--red); border-color: #f1d7d8; background: #fff7f7; }
.button.wide { width: 100%; }
.button.small { min-height: 32px; padding: 5px 11px; font-size: 12px; }

.flash { margin: -14px 0 24px; padding: 12px 15px; border-radius: 10px; font-weight: 650; }
.flash.success { color: #136342; background: #ddf6e9; }
.flash.error { color: #a03239; background: #fde4e5; }

.kpi-grid { margin-bottom: 24px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi-card { min-height: 148px; padding: 22px; display: flex; align-items: flex-start; gap: 16px; border: 1px solid var(--line); border-radius: 15px; background: var(--white); box-shadow: 0 8px 30px rgba(23,32,51,.035); }
.kpi-card.lime { border-color: #dcebba; background: linear-gradient(145deg, #f5ffe1, #fff); }
.kpi-icon { width: 36px; height: 36px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 10px; color: #62751d; background: var(--lime-soft); font-weight: 900; }
.kpi-card span, .kpi-card small { display: block; color: var(--muted); }
.kpi-card span { margin-bottom: 9px; font-size: 12px; font-weight: 700; }
.kpi-card strong { display: block; font-size: 32px; line-height: 1; letter-spacing: -.04em; }
.kpi-card small { margin-top: 10px; font-size: 11px; }

.dashboard-grid { margin-bottom: 24px; display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(260px, .7fr); gap: 18px; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--white); box-shadow: 0 8px 35px rgba(23,32,51,.035); }
.trend-panel, .movement-panel { min-height: 310px; padding: 24px; }
.panel-header { margin-bottom: 22px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.panel-header .eyebrow { margin-bottom: 4px; }
.status-pill { padding: 5px 9px; display: inline-flex; align-items: center; border-radius: 999px; color: #58701b; background: var(--lime-soft); font-size: 10px; font-weight: 800; white-space: nowrap; }
.muted-pill { color: #687085; background: #eceef2; }
.status-failed { color: #a03239; background: #fde4e5; }
.status-processing, .status-queued { color: #76531b; background: #fff0ca; }
.trend-chart { height: 205px; padding-top: 18px; display: flex; align-items: flex-end; gap: clamp(8px, 2vw, 22px); border-bottom: 1px solid var(--line); background: repeating-linear-gradient(to bottom, #fff 0, #fff 49px, #f0f1ec 50px); }
.trend-column { height: 100%; flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 7px; }
.trend-column b { font-size: 10px; color: #697187; }
.trend-column i { width: min(26px, 75%); min-height: 8px; border-radius: 7px 7px 2px 2px; background: linear-gradient(180deg, var(--lime), #87b52f); }
.trend-column span { margin-bottom: -27px; color: #8a92a2; font-size: 9px; white-space: nowrap; }
.movement-list { display: grid; gap: 15px; }
.movement-list > div { padding-bottom: 12px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid #eff0ec; }
.movement-list p { margin: 0; color: #677086; }
.movement-list strong { color: var(--ink); font-size: 18px; }
.movement-dot { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; font-weight: 900; }
.movement-dot.up, .delta.up { color: var(--green); background: #e0f6eb; }
.movement-dot.down, .delta.down { color: var(--red); background: #fde7e8; }
.movement-dot.same, .delta.same { color: #6f788b; background: #eef0f2; }
.movement-dot.new, .delta.new { color: #6e5b19; background: #fff3c7; }
.run-note { margin: 16px 0 0; color: #8b93a2; font-size: 10px; }

.rankings-panel { overflow: hidden; }
.table-heading { margin: 0; padding: 22px 24px; align-items: center; border-bottom: 1px solid var(--line); }
.header-actions, .filter-form { display: flex; align-items: center; gap: 9px; }
input, select, textarea { width: 100%; min-height: 42px; padding: 9px 12px; color: var(--ink); border: 1px solid #d8dce3; border-radius: 9px; outline: none; background: var(--white); }
textarea { resize: vertical; line-height: 1.65; }
input:focus, select:focus, textarea:focus { border-color: #9bc83c; box-shadow: 0 0 0 3px rgba(182,238,71,.2); }
.filter-form input { width: 190px; }
.filter-form select { width: 150px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 18px; color: #8a92a2; background: #fafbf8; font-size: 10px; letter-spacing: .07em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 16px 18px; border-top: 1px solid #edefe9; color: #555f74; vertical-align: middle; }
td strong, td small { display: block; }
td strong { color: var(--ink); }
td small { margin-top: 3px; color: #969dac; font-size: 10px; }
.client-cell { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.client-cell i { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; color: #4c5c1d; background: var(--lime-soft); font-size: 10px; font-style: normal; font-weight: 800; }
.rank-badge { min-width: 43px; padding: 7px 9px; display: inline-block; border-radius: 8px; color: #576177; background: #f0f2f4; font-weight: 800; text-align: center; }
.rank-badge.top { color: #52691b; background: var(--lime-soft); }
.device-rank { display: flex; align-items: center; gap: 6px; }
.delta { min-width: 38px; padding: 4px 7px; display: inline-block; border-radius: 7px; font-size: 11px; font-weight: 800; text-align: center; }
.result-link { max-width: 230px; display: block; overflow: hidden; color: #596e1f; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { min-height: 220px; padding: 32px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; color: var(--muted); text-align: center; }
.empty-state.compact { min-height: 150px; }
.empty-state strong { color: var(--ink); font-size: 17px; }
.empty-icon { width: 46px; height: 46px; margin-bottom: 8px; display: grid; place-items: center; border-radius: 14px; color: #64751f; background: var(--lime-soft); }

.client-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.client-card { padding: 22px; border: 1px solid var(--line); border-radius: 15px; background: var(--white); box-shadow: 0 8px 30px rgba(23,32,51,.035); }
.client-card-head { display: flex; align-items: center; justify-content: space-between; }
.client-avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: #4d6019; background: var(--lime-soft); font-weight: 900; }
.client-card h2 { margin: 18px 0 2px; }
.client-card > a { color: #748037; font-size: 13px; }
.client-stats { margin: 20px 0; padding: 14px 0; display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.client-stats div + div { padding-left: 16px; border-left: 1px solid var(--line); }
.client-stats strong, .client-stats span { display: block; }
.client-stats strong { font-size: 22px; }
.client-stats span { color: var(--muted); font-size: 10px; }
.client-card dl { margin: 0; display: grid; gap: 9px; }
.client-card dl div { display: flex; justify-content: space-between; gap: 12px; }
.client-card dt { color: #9097a6; }
.client-card dd { margin: 0; color: #4d566a; text-align: right; }
.keyword-preview { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 6px; }
.keyword-preview span, .keyword-preview small { padding: 4px 7px; border-radius: 6px; color: #697187; background: #f1f3ed; font-size: 9px; }
.keyword-preview small { color: #65731f; background: var(--lime-soft); }
.card-actions { margin-top: 20px; display: flex; gap: 8px; }

.modal { width: min(600px, calc(100% - 30px)); padding: 0; border: 0; border-radius: 18px; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(17,24,38,.65); backdrop-filter: blur(3px); }
.modal form { padding: 26px; }
.modal form + form { padding-top: 0; }
.modal-head { margin-bottom: 21px; display: flex; justify-content: space-between; }
.modal-head button { width: 32px; height: 32px; border: 0; border-radius: 9px; background: #f0f2ed; cursor: pointer; font-size: 20px; }
.stack-form { display: grid; gap: 15px; }
.stack-form label { display: grid; gap: 6px; color: #4e586c; font-size: 12px; font-weight: 750; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.check-row { display: flex !important; align-items: center; gap: 9px !important; }
.check-row input { width: 17px; min-height: 17px; accent-color: #8fbe31; }
.form-help { margin: -3px 0 0; color: var(--muted); font-size: 11px; }
.device-note { padding: 12px 14px; display: flex; align-items: center; gap: 10px; border: 1px solid #dfebc7; border-radius: 10px; color: #54651d; background: #f6ffe6; }
.device-note > span { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--lime); font-weight: 900; }
.device-note strong, .device-note small { display: block; }
.device-note small { color: #79835c; font-size: 10px; }
.field-error { color: var(--red); font-size: 12px; }
.row-actions { display: flex; gap: 6px; }
.icon-button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); cursor: pointer; }
.danger-text { color: var(--red); }
.pagination { padding: 15px 22px; border-top: 1px solid var(--line); }
.pagination nav > div:first-child { display: none; }
.pagination nav > div:last-child { display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 12px; }
.pagination svg { width: 17px; }
.pagination span[aria-current] span { color: var(--ink); background: var(--lime-soft); }
.pagination a, .pagination span > span { padding: 7px 10px; border: 1px solid var(--line); }

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 25px; background: radial-gradient(circle at 20% 10%, #2d3953, var(--ink) 45%); }
.auth-card { width: min(430px, 100%); padding: 38px; border-radius: 20px; background: var(--white); box-shadow: 0 30px 80px rgba(0,0,0,.28); }
.auth-brand { margin-bottom: 42px; color: var(--ink); }
.auth-card h1 { font-size: 34px; }

@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .client-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 780px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; z-index: 20; width: 244px; transform: translateX(-105%); transition: transform .2s; }
    body.menu-open .sidebar { transform: translateX(0); }
    .main-content { padding: 18px 16px 45px; }
    .mobile-header { margin-bottom: 28px; display: flex; align-items: center; justify-content: space-between; }
    .mobile-header .brand { color: var(--ink); }
    .mobile-menu { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); }
    .page-header { align-items: flex-start; flex-direction: column; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .client-grid { grid-template-columns: 1fr; }
    .table-heading, .header-actions, .filter-form { align-items: stretch; flex-direction: column; }
    .filter-form input, .filter-form select { width: 100%; }
    .form-grid, .form-grid.three { grid-template-columns: 1fr; }
}

@media (max-width: 500px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .kpi-card { min-height: 120px; }
    .auth-card { padding: 28px 22px; }
}
