:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --accent: #f59e0b;
    --danger: #dc2626;
    --text: #1e293b;
    --muted: #64748b;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --radius: 16px;
    --tabbar-h: 72px;
    --topbar-h: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    min-height: 100vh;
    padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.55rem; margin: 0.15rem 0; letter-spacing: -0.02em; }
h2 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.tight-top { margin-top: 10px; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    min-height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    max-width: 720px;
    margin: 0 auto;
}
.brand img { height: 18px; width: auto; display: block; }
.icon-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: var(--muted);
    font-size: 1.2rem;
}

.page {
    max-width: 720px;
    margin: 0 auto;
    padding: 14px 14px 0;
}
.page-head { margin-bottom: 2px; }
.back-link { display: inline-block; color: var(--muted); font-size: 0.92rem; min-height: 44px; line-height: 44px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 16px;
    border-radius: 14px;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    text-align: center;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-accent { background: var(--accent); color: #111; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; }
label > span { color: var(--muted); font-weight: 600; }
label > small.muted { font-size: 0.8rem; font-weight: 500; }
input, select, textarea {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    font: inherit;
    background: #fff;
    color: var(--text);
}
textarea { min-height: 110px; resize: vertical; }
.check-row {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    min-height: 48px;
}
.check-row input { width: auto; min-height: auto; }

.form-card, .info-card, .stat-card, .block {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.form-card { padding: 14px; }
.info-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 14px;
}
.info-card .full { grid-column: 1 / -1; }
.info-card span { display: block; font-size: 0.8rem; margin-bottom: 2px; }
.block { padding: 14px; }
.block-title { margin-bottom: 10px; color: var(--muted); }
.block-title.danger { color: var(--danger); }
.block-hint { margin: -4px 0 12px; color: var(--muted); font-size: 0.88rem; }
.task-badge {
    display: inline-flex;
    margin-top: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-dark);
    font-size: 0.85rem;
    font-weight: 700;
}
.task-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.task-card.is-overdue { border-color: #fecaca; background: #fff7f7; }
.task-card.is-today { border-color: #bfdbfe; }
.task-main { display: block; padding: 14px; color: inherit; }
.task-action {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--primary-dark);
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}
.task-contact, .task-resolve {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 0 14px 14px;
}
.task-resolve { grid-template-columns: 1fr; }
.task-resolve form:first-child,
.task-contact .btn:first-child { grid-column: 1 / -1; }
@media (min-width: 480px) {
    .task-resolve { grid-template-columns: 1fr 1fr 1fr; }
    .task-resolve form:first-child { grid-column: auto; }
}
.task-highlight { border-color: #bfdbfe; background: #f8fbff; }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.lead-card {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
    color: inherit;
    transition: transform 0.12s ease;
    touch-action: pan-y;
}
.lead-card.is-overdue { border-color: #fecaca; background: #fff7f7; }
.lead-card.is-today { border-color: #bfdbfe; }
.lead-card-top, .lead-card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.lead-id {
    color: var(--muted);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.lead-id-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
}
.lead-card-meta {
    margin: 6px 0;
    color: var(--muted);
    font-size: 0.9rem;
}
.remind-pill {
    background: rgba(37, 99, 235, 0.08);
    color: var(--primary-dark);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.chip, .chip-filter {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}
.chip-filter {
    min-height: 40px;
    padding: 0 14px;
    background: #fff;
    border: 1px solid var(--border);
    color: var(--muted);
}
.chip-filter.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.chips-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.chips-scroll::-webkit-scrollbar { display: none; }

.st-new { background: #e2e8f0; color: #334155; }
.st-sent { background: #dbeafe; color: #1d4ed8; }
.st-waiting { background: #fef3c7; color: #b45309; }
.st-progress { background: #ede9fe; color: #6d28d9; }
.st-won { background: #dcfce7; color: #15803d; }
.st-lost { background: #fee2e2; color: #b91c1c; }
.st-forgotten { background: #f1f5f9; color: #64748b; }

.search-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.action-grid .btn-block { width: 100%; }

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.stat-card {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stat-card strong { font-size: 1.4rem; letter-spacing: -0.02em; }
.stat-card.accent { grid-column: 1 / -1; background: linear-gradient(135deg, #2563eb, #1e40af); color: #fff; border: none; }
.stat-card.accent .muted { color: rgba(255,255,255,0.8); }

.funnel, .plain-list, .timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.funnel-row, .plain-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.funnel-row:last-child, .plain-list li:last-child { border-bottom: 0; }
.timeline li { padding-bottom: 10px; border-bottom: 1px solid var(--border); }

.empty, .empty-inline {
    text-align: center;
    color: var(--muted);
    padding: 28px 12px;
}
.empty { background: var(--card); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty .btn { margin-top: 12px; }

.flash {
    padding: 12px 14px;
    border-radius: 14px;
    margin-bottom: 4px;
    font-weight: 600;
}
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: end;
    gap: 2px;
    min-height: var(--tabbar-h);
    padding: 8px 6px calc(8px + var(--safe-bottom));
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
}
.tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 52px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 14px;
}
.tabbar a.active { color: var(--primary); }
.tab-ico { font-size: 1.1rem; line-height: 1; }
.tab-fab {
    position: relative;
    top: -14px;
}
.fab-plus {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 500;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.sheet.hidden { display: none; }
.sheet { position: fixed; inset: 0; z-index: 80; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.45); }
.sheet-panel {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 10px 16px calc(20px + var(--safe-bottom));
    max-height: 85vh;
    overflow: auto;
    animation: sheetUp 0.2s ease;
}
.sheet-handle {
    width: 42px; height: 4px; border-radius: 999px;
    background: #cbd5e1; margin: 4px auto 14px;
}
@keyframes sheetUp {
    from { transform: translateY(20px); opacity: 0.6; }
    to { transform: translateY(0); opacity: 1; }
}

.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(180deg, #f8fafc, #ffffff);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 24px;
    box-shadow: var(--shadow);
}
.auth-logo { height: 22px; width: auto; margin-bottom: 14px; }
.auth-card h1 { margin-bottom: 4px; }

@media (min-width: 768px) {
    .action-grid { grid-template-columns: repeat(3, 1fr); }
}
