/* ============================================================
   ПФ SaaS — Main Stylesheet
   ============================================================ */

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-bg:          #0f1117;
    --color-bg-card:     #1a1d27;
    --color-bg-sidebar:  #13151f;
    --color-border:      #2a2d3d;
    --color-text:        #e2e4f0;
    --color-text-muted:  #6b7080;
    --color-primary:     #6366f1;
    --color-primary-h:   #4f52e0;
    --color-success:     #10b981;
    --color-warning:     #f59e0b;
    --color-danger:      #ef4444;
    --color-info:        #3b82f6;
    --sidebar-width:     240px;
    --radius:            8px;
    --shadow:            0 4px 24px rgba(0,0,0,.35);
}

html { font-size: 15px; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.55;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────────── */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-bg-sidebar);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-logo {
    padding: 1.25rem 1.25rem .75rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    border-bottom: 1px solid var(--color-border);
}

.logo-link {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    text-decoration: none;
}

.role-badge {
    font-size: .7rem;
    background: var(--color-primary);
    color: #fff;
    padding: .15rem .45rem;
    border-radius: 4px;
    font-weight: 600;
}

.sidebar-nav {
    flex: 1;
    padding: .75rem 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .6rem 1.25rem;
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: 0;
    transition: background .15s, color .15s;
    font-size: .9rem;
}

.nav-item:hover { background: rgba(255,255,255,.05); color: var(--color-text); text-decoration: none; }
.nav-item.active { background: rgba(99,102,241,.18); color: var(--color-primary); font-weight: 600; }

.nav-icon { font-size: 1.05rem; width: 1.4rem; text-align: center; flex-shrink: 0; }

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.admin-name {
    font-size: .85rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.balance-chip {
    font-size: .85rem;
    color: var(--color-text-muted);
}

.balance-chip strong { color: var(--color-success); }

.btn-logout {
    background: none;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    padding: .4rem .75rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .85rem;
    transition: background .15s, color .15s;
}

.btn-logout:hover { background: rgba(239,68,68,.15); color: var(--color-danger); border-color: var(--color-danger); }

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 2rem 2.5rem;
    max-width: calc(100vw - var(--sidebar-width));
}

/* ── Page header ───────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
}

.page-subtitle {
    display: block;
    font-size: .85rem;
    color: var(--color-text-muted);
    margin-top: .2rem;
}

.header-actions { display: flex; gap: .5rem; align-items: center; }

.breadcrumb-link {
    font-size: .85rem;
    color: var(--color-text-muted);
    display: block;
    margin-bottom: .35rem;
}
.breadcrumb-link:hover { color: var(--color-primary); }

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 1.5rem;
}
.tab {
    padding: .55rem 1.25rem;
    font-size: .9rem;
    font-weight: 500;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    text-decoration: none;
    transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--color-primary); }
.tab-active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* ── Calendar grid ──────────────────────────────────────────── */
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.cal-head {
    text-align: center;
    font-size: .78rem;
    font-weight: 600;
    color: var(--color-text-muted);
    padding: 4px 0 8px;
}
.cal-cell {
    border-radius: 6px;
    padding: 6px 4px 4px;
    min-height: 58px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    position: relative;
}
.cal-empty { background: transparent; border-color: transparent; }
.cal-future { background: #f8fafc; opacity: .5; }
.cal-today { outline: 2px solid var(--color-primary); outline-offset: -1px; }
.cal-day-num { font-size: .78rem; color: var(--color-text-muted); font-weight: 600; }
.cal-today .cal-day-num { color: var(--color-primary); }
.cal-day-clicks { font-size: 1rem; font-weight: 700; margin-top: 4px; }

/* ── Clicks matrix ──────────────────────────────────────────── */
.clicks-matrix { table-layout: auto; }
.clicks-matrix .kw-col  { min-width: 180px; max-width: 240px; }
.clicks-matrix .day-col { min-width: 52px; width: 52px; text-align: center; }
.clicks-matrix .col-today { background: #eff6ff !important; }
.clicks-matrix .col-weekend { }
.cm-cell {
    display: inline-block;
    padding: 2px 5px;
    border-radius: 4px;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}
.cm-done    { background: #dcfce7; color: #166534; }
.cm-partial { background: #fef9c3; color: #854d0e; }
.cm-branded { background: #e0e7ff; color: #3730a3; }
.cm-zero    { background: #f1f5f9; color: #94a3b8; }

/* ── Keyword table inline inputs ────────────────────────────── */
.kw-table .inline-input {
    padding: 3px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: .82rem;
    background: #f8fafc;
    transition: border-color .15s, background .15s;
}
.kw-table .inline-input:focus {
    outline: none;
    border-color: var(--color-primary);
    background: #fff;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .55rem 1.1rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .88rem;
    font-weight: 500;
    transition: opacity .15s, transform .1s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { opacity: .88; text-decoration: none; }
.btn:active { transform: scale(.97); }

.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-h); }
.btn-secondary { background: #252835; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-success   { background: var(--color-success); color: #fff; }
.btn-warning   { background: var(--color-warning); color: #000; }
.btn-danger    { background: var(--color-danger);  color: #fff; }
.btn-info      { background: var(--color-info);    color: #fff; }

.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem .75rem;
    border-bottom: 1px solid var(--color-border);
}

.card-title { font-size: 1rem; font-weight: 600; }

.card-body { padding: 1.25rem; }

.cards-row {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.card-half { flex: 1 1 calc(50% - .625rem); min-width: 280px; }
.card-full { flex: 1 1 100%; }

/* ── Stats Grid ─────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card-primary { border-color: var(--color-primary); }
.stat-card-success { border-color: var(--color-success); }

.stat-icon { font-size: 1.75rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: .8rem; color: var(--color-text-muted); margin-top: .1rem; }

.stats-mini { font-size: .9rem; color: var(--color-text-muted); }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}

.table th, .table td {
    padding: .65rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-text-muted);
    background: rgba(255,255,255,.02);
}

.table tbody tr:hover { background: rgba(255,255,255,.025); }
.table-sm th, .table-sm td { padding: .45rem .75rem; }

.row-inactive { opacity: .5; }
.empty-cell { text-align: center; color: var(--color-text-muted); padding: 2rem !important; }

.table-note { font-size: .8rem; color: var(--color-text-muted); margin-top: .5rem; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 4px;
    font-size: .75rem;
    font-weight: 600;
}

.badge-success { background: rgba(16,185,129,.15); color: var(--color-success); }
.badge-danger  { background: rgba(239,68,68,.15);  color: var(--color-danger); }
.badge-warning { background: rgba(245,158,11,.15); color: var(--color-warning); }
.badge-info    { background: rgba(59,130,246,.15); color: var(--color-info); }
.badge-muted   { background: rgba(255,255,255,.06); color: var(--color-text-muted); }

/* ── Alerts ──────────────────────────────────────────────────── */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .9rem;
}

.alert-success { background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.3); color: var(--color-success); }
.alert-error   { background: rgba(239,68,68,.12);  border: 1px solid rgba(239,68,68,.3);  color: var(--color-danger); }
.alert-warning { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); color: var(--color-warning); }
.alert-info    { background: rgba(59,130,246,.12); border: 1px solid rgba(59,130,246,.3); color: var(--color-info); }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }

.form-label {
    display: block;
    font-size: .85rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: .35rem;
}

.form-input {
    width: 100%;
    background: #1e2130;
    border: 1px solid var(--color-border);
    color: var(--color-text);
    padding: .55rem .85rem;
    border-radius: var(--radius);
    font-size: .9rem;
    transition: border-color .15s;
    outline: none;
}

.form-input:focus { border-color: var(--color-primary); }
.form-input:disabled { opacity: .5; cursor: not-allowed; }
.form-input-sm { padding: .3rem .65rem; font-size: .82rem; width: auto; }

.form-hint { font-size: .78rem; color: var(--color-text-muted); margin-top: .25rem; display: block; }

.form-actions { margin-top: 1.25rem; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
    font-size: .9rem;
    color: var(--color-text);
}

.input-with-suffix {
    display: flex;
    align-items: center;
}
.input-with-suffix .form-input { border-radius: var(--radius) 0 0 var(--radius); }
.input-suffix {
    background: #252835;
    border: 1px solid var(--color-border);
    border-left: none;
    padding: .55rem .75rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--color-text-muted);
    font-size: .9rem;
}

hr.divider { border: none; border-top: 1px solid var(--color-border); margin: 1.25rem 0; }
.section-title { font-size: .95rem; font-weight: 600; margin-bottom: .25rem; }

/* ── Modals ──────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 200;
    backdrop-filter: blur(2px);
}

.modal {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 300;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal-lg { max-width: 700px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 { font-size: 1rem; font-weight: 600; }

.modal-close {
    background: none; border: none; color: var(--color-text-muted);
    font-size: 1.4rem; cursor: pointer; line-height: 1; padding: 0;
}
.modal-close:hover { color: var(--color-danger); }

.modal-body { padding: 1.25rem; }
.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

/* ── Auth pages ──────────────────────────────────────────────── */
.auth-page {
    background: radial-gradient(ellipse at 60% 20%, #1a1060 0%, var(--color-bg) 65%);
}

.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2rem 2.25rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.auth-logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-primary);
    text-align: center;
    margin-bottom: .5rem;
}

.auth-title {
    font-size: 1.2rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--color-text-muted);
}

.auth-form .form-group { margin-bottom: 1.1rem; }
.auth-footer { text-align: center; margin-top: 1.25rem; font-size: .88rem; color: var(--color-text-muted); }

/* ── Projects grid ───────────────────────────────────────────── */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.project-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: border-color .15s;
}

.project-card:hover { border-color: var(--color-primary); }
.project-card.inactive { opacity: .6; }

.project-card-header { margin-bottom: .75rem; }
.project-name { font-size: 1rem; font-weight: 600; display: block; }
.project-domain { font-size: .8rem; color: var(--color-text-muted); }

.project-stats { display: flex; gap: 1rem; margin-bottom: 1rem; }
.stat { text-align: center; flex: 1; }
.stat .stat-value { font-size: 1.1rem; font-weight: 700; display: block; }
.stat .stat-label { font-size: .72rem; color: var(--color-text-muted); }

.project-card-actions { display: flex; gap: .4rem; }

/* ── Keywords ────────────────────────────────────────────────── */
.keyword-phrase { font-weight: 500; }
.keyword-brand  { font-size: .78rem; color: var(--color-text-muted); }
.keyword-url    { font-size: .78rem; color: var(--color-text-muted); font-family: monospace; }

.action-buttons { display: flex; gap: .3rem; flex-wrap: wrap; }

/* ── Filter bar ──────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.filter-group { display: flex; flex-direction: column; gap: .25rem; }

/* ── Wallet ──────────────────────────────────────────────────── */
.wallet-top {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    align-items: start;
}

.balance-card {
    background: linear-gradient(135deg, #1c1f35, #252840);
    border: 1px solid var(--color-primary);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}

.balance-label { font-size: .85rem; color: var(--color-text-muted); }
.balance-amount { font-size: 2rem; font-weight: 800; color: var(--color-success); }

.balance-display {
    font-size: 1rem;
    margin-bottom: .5rem;
    padding: .5rem;
    background: rgba(255,255,255,.04);
    border-radius: var(--radius);
}

.deposit-card {}

.quick-amounts { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }

.amount-positive { color: var(--color-success); font-weight: 500; }
.amount-negative { color: var(--color-danger);  font-weight: 500; }
.amount-warning  { color: var(--color-warning); }

/* ── Status dots ─────────────────────────────────────────────── */
.status-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}
.dot-green { background: var(--color-success); box-shadow: 0 0 6px var(--color-success); }
.dot-red   { background: var(--color-danger); }

/* ── Admin copies ────────────────────────────────────────────── */
.url-link {
    color: var(--color-info);
    font-size: .8rem;
    font-family: monospace;
}

/* ── Pricing ─────────────────────────────────────────────────── */
.pricing-hierarchy {
    padding-left: 1.25rem;
    color: var(--color-text-muted);
    font-size: .9rem;
    line-height: 2;
}
.pricing-hierarchy strong { color: var(--color-text); }

/* ── Quick links ─────────────────────────────────────────────── */
.quick-links { display: flex; flex-direction: column; gap: .4rem; }
.quick-link {
    display: block;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    background: rgba(255,255,255,.04);
    color: var(--color-text);
    text-decoration: none;
    font-size: .9rem;
    transition: background .15s;
}
.quick-link:hover { background: rgba(99,102,241,.15); color: var(--color-primary); text-decoration: none; }

/* ── Impersonate bar ─────────────────────────────────────────── */
.impersonate-bar {
    background: #7c3aed;
    color: #fff;
    padding: .5rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .88rem;
    position: sticky;
    top: 0;
    z-index: 500;
}

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--color-text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h2 { font-size: 1.2rem; margin-bottom: .5rem; color: var(--color-text); }
.empty-state p { margin-bottom: 1.25rem; }

/* ── Error page ──────────────────────────────────────────────── */
.error-code { font-size: 5rem; font-weight: 900; color: var(--color-primary); opacity: .4; }

/* ── Text helpers ────────────────────────────────────────────── */
.text-muted  { color: var(--color-text-muted); }
.text-small  { font-size: .82rem; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar { width: 64px; }
    .nav-label, .sidebar-footer .admin-name, .sidebar-footer .balance-chip,
    .sidebar-logo .logo-link span, .role-badge { display: none; }
    .main-content { margin-left: 64px; padding: 1rem 1.25rem; max-width: calc(100vw - 64px); }
    .wallet-top { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .main-content { padding: .75rem; }
    .projects-grid { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; }
}

/* ── Alpine.js transitions ───────────────────────────────────── */
[x-cloak] { display: none !important; }
