/* ============================================================
   SALES TRACKER — Design System
   Based on: modern_minimal_saas dashboard UI
   ============================================================ */

/* ─── Design Tokens ─── */
:root {
    --font:            'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
    --bg:              #F6F8FB;
    --surface:         #FFFFFF;
    --border:          #EEF1F5;
    --radius:          14px;
    --radius-sm:       8px;
    --radius-pill:     999px;
    --shadow:          0 2px 8px rgba(15, 23, 42, 0.05);
    --shadow-hover:    0 6px 18px rgba(47, 128, 237, 0.12);
    --shadow-lg:       0 8px 30px rgba(15, 23, 42, 0.10);

    --primary:         #2F80ED;
    --primary-light:   #56A3FF;
    --primary-bg:      #F3F8FF;
    --primary-hover:   #1A6FDB;
    --accent:          #4DA3FF;
    --success:         #27AE60;
    --success-bg:      #EAFBF1;
    --warning:         #F2C94C;
    --warning-bg:      #FFF9E6;
    --danger:          #EB5757;
    --danger-bg:       #FEF0F0;

    --text:            #1F2937;
    --text-secondary:  #6B7280;
    --text-muted:      #9CA3AF;

    --nav-h:           64px;
    --outer-pad:       24px;
    --section-gap:     16px;
    --card-gap:        12px;

    --transition:      all 0.2s ease;
}
*{
    font-family: var(--font);
}

/* ─── Reset inside root ─── */
.stm-root, .stm-root *, .stm-root *::before, .stm-root *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
.stm-root {
    
    font-size: 14px;
    line-height: 1.4;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   HEADER
   ============================================================ */
.st-header {
    height: var(--nav-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--outer-pad);
    position: sticky;
    top: 0;
    z-index: 100;
}

.st-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    text-decoration: none;
    flex-shrink: 0;
}
.st-logo-dot {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
}
.st-logo-dot svg { width: 18px; height: 18px; color: #fff; }

/* ─── Nav tabs ─── */
.st-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.st-tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 18px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    white-space: nowrap;
    cursor: pointer;
    border: none;
    background: transparent;
    
}
.st-tab:hover { color: var(--text); background: var(--bg); }
.st-tab.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(47, 128, 237, 0.25);
}
.st-tab-icon { font-size: 16px; line-height: 1; }

/* ─── Header right ─── */
.st-header-right {
    /* display: flex; */
    display: none;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.st-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #F3F6FA;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}
.st-icon-btn:hover { background: #E8F1FF; color: var(--primary); }
.st-icon-btn svg { width: 18px; height: 18px; }

.st-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.st-main {
    padding: var(--outer-pad);
    max-width: 1440px;
    margin: 0 auto;
    min-height: calc(100vh - var(--nav-h) - 120px);
}

/* ============================================================
   FOOTER
   ============================================================ */
.st-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 20px var(--outer-pad);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}
.st-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.st-footer a:hover { text-decoration: underline; }
.st-footer-links { display: flex; gap: 20px; }

/* ============================================================
   CONTROLS
   ============================================================ */
.ctrl-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: var(--section-gap);
}

.ctrl-sel {
    height: 36px;
    padding: 0 12px;
    border-radius: 18px;
    border: none;
    background: #F3F6FA;
    font-size: 14px;
    
    font-weight: 500;
    color: var(--text);
    outline: none;
    cursor: pointer;
    transition: var(--transition);
    appearance: auto;
}
.ctrl-sel:focus {
    box-shadow: 0 0 0 3px rgba(47,128,237,.15);
}
.ctrl-sel.wide { width: 100%; border-radius: var(--radius-sm); height: 40px; }

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 20px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(47,128,237,.25);
    transform: translateY(-1px);
}

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #219B54; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: #F3F6FA; color: var(--text); }

.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-lg { padding: 12px 28px; font-size: 15px; }

/* ============================================================
   PAGE TITLE
   ============================================================ */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 12px;
    flex-wrap: wrap;
}
.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}
.page-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ============================================================
   METRIC CARDS (top row)
   ============================================================ */
.metric-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--card-gap);
    margin-bottom: var(--section-gap);
}

.metric-card {
    height: 96px;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    transition: var(--transition);
}
.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}
.metric-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--primary-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.metric-body { flex: 1; min-width: 0; }
.metric-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.metric-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

/* ============================================================
   DASHBOARD TABLE — CHANNEL BLOCK
   ============================================================ */
.dash-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: var(--section-gap);
    overflow: hidden;
    transition: var(--transition);
}
.dash-card:hover { box-shadow: var(--shadow-hover); }

.dash-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.dash-card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}
.dash-card-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    background: var(--primary-bg);
    color: var(--primary);
}

/* ─── Table ─── */
.tbl-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.dash-tbl {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.dash-tbl th,
.dash-tbl td {
    height: 44px;
    padding: 0 14px;
    text-align: right;
    white-space: nowrap;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}

.dash-tbl th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #FAFBFC;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}

.dash-tbl .col-metric {
    text-align: left;
    position: sticky;
    left: 0;
    z-index: 3;
    min-width: 210px;
    background: inherit;
}
.dash-tbl th.col-metric { z-index: 4; }

/* row types */
.dash-tbl .row-calc td { background: #FAFBFD; }
.dash-tbl .row-calc .col-metric { background: #FAFBFD; }
.dash-tbl .row-input td { background: var(--surface); }
.dash-tbl .row-input .col-metric { background: var(--surface); }

.dash-tbl tbody tr { transition: var(--transition); }
.dash-tbl tbody tr:hover td { background: #E0ECFF !important; }
.dash-tbl tbody tr:hover .col-metric { background: #E0ECFF !important; }

/* metric name styling */
.metric-name {
    display: flex;
    align-items: center;
    gap: 8px;
}
.metric-name .m-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.m-dot-input  { background: var(--primary); }
.m-dot-calc   { background: var(--text-muted); }

.formula-tag {
    display: inline-block;
    padding: 1px 6px;
    background: var(--primary-bg);
    color: var(--primary);
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
    margin-left: 4px;
}

/* week columns */
.col-wplan { color: var(--text-muted); font-weight: 400; min-width: 72px; }
.col-wfact { font-weight: 600; color: var(--text); min-width: 72px; }
.col-fact  { font-weight: 700; color: var(--text); min-width: 88px; }
/* completion */
.col-pct { font-weight: 700; min-width: 96px; }
.pct-green  { color: var(--success); }
.pct-yellow { color: #D4A017; }
.pct-red    { color: var(--danger); }

/* progress bar in completion */
.pct-bar-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
}
.pct-bar {
    width: 48px;
    height: 4px;
    border-radius: 4px;
    background: #EEF3F8;
    overflow: hidden;
}
.pct-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
}

/* ============================================================
   WEEKLY FACT DRILL-DOWN
   ============================================================ */

/* Clickable Ф.Тx header cells */
.wfact-header {
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}
.wfact-header:hover {
    background: var(--primary-bg) !important;
    color: var(--primary);
}
.wfact-header.active {
    background: var(--primary-bg) !important;
    color: var(--primary);
}
.wfact-arrow {
    display: inline-block;
    margin-left: 4px;
    font-size: 9px;
    vertical-align: middle;
    transition: transform 0.2s ease;
}

/* Inline daily columns */
.col-day {
    background: var(--primary-bg) !important;
    font-size: 11px;
    min-width: 56px;
    max-width: 80px;
    text-align: right;
    white-space: nowrap;
    border-left: 1px dashed color-mix(in srgb, var(--primary) 25%, transparent);
}
.col-day:last-of-type {
    border-right: 1px dashed color-mix(in srgb, var(--primary) 25%, transparent);
}
.col-day-header {
    font-size: 10px !important;
    font-weight: 700 !important;
    color: var(--primary) !important;
    letter-spacing: 0.02em;
}
.col-day-calc {
    color: var(--text-muted);
    font-style: italic;
}
.col-day-loading {
    color: var(--text-muted);
    font-style: italic;
    animation: dayPulse 0.8s ease infinite alternate;
}
@keyframes dayPulse {
    from { opacity: 0.4; }
    to   { opacity: 1; }
}

/* ============================================================
   FORM CARD
   ============================================================ */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.form-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 12px;
    flex-wrap: wrap;
}

.form-body { display: flex; flex-direction: column; gap: 20px; }

.form-row-top {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.form-row-top .field-group { min-width: 180px; flex: 1; max-width: 300px; }

/* ─── Fields ─── */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.field-input {
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    
    color: var(--text);
    outline: none;
    transition: var(--transition);
    width: 100%;
    background: var(--surface);
}
.field-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(47,128,237,.12);
}

.fields-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--card-gap);
}

.form-actions { padding-top: 4px; }

/* ─── Plan preview ─── */
.plan-preview {
    background: #FAFBFD;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
}
.plan-preview h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.fields-grid.preview { gap: 8px; }
.preview-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
}
.preview-label { color: var(--text-secondary); }
.preview-val   { font-weight: 600; color: var(--text); }

/* ============================================================
   CHANNEL LIST
   ============================================================ */
.ch-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.ch-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 18px;
    background: #FAFBFD;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: var(--transition);
}
.ch-row:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.ch-name { font-weight: 600; flex: 1; font-size: 15px; }
.ch-mgr  { color: var(--text-secondary); font-size: 13px; flex: 1; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
}
.badge-ok  { background: var(--success-bg); color: var(--success); }
.badge-off { background: var(--danger-bg);  color: var(--danger); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-ov {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn .15s;
}

.modal-box {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 28px;
    width: 460px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: slideUp .2s ease;
}
.modal-box h3 { font-size: 18px; font-weight: 700; }

.modal-acts {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 8px;
}

/* ============================================================
   LOADER / EMPTY / TOAST / LOGIN
   ============================================================ */
.st-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 60px 0;
    color: var(--text-muted);
    font-size: 14px;
}
.st-spin {
    width: 22px;
    height: 22px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .55s linear infinite;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 15px;
}
.empty-state.err { color: var(--danger); }

.st-toast {
    position: fixed;
    top: 24px;
    right: 24px;
    padding: 12px 22px;
    border-radius: 12px;
    
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    z-index: 99999;
    box-shadow: var(--shadow-lg);
    animation: slideIn .2s ease;
    transition: opacity .3s;
}
.toast-ok  { background: var(--success); }
.toast-err { background: var(--danger); }
.toast-out { opacity: 0; }

.stm-login-prompt {
    text-align: center;
    padding: 80px 20px;
    font-size: 16px;
    color: var(--text-secondary);
}
.stm-login-prompt a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}
.stm-login-prompt a:hover { text-decoration: underline; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
    from { opacity: 0; transform: translateX(16px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
    .st-header { padding: 0 16px; }
    .st-main   { padding: 16px; }
    .st-footer { padding: 16px; flex-direction: column; gap: 8px; text-align: center; }
}

@media (max-width: 768px) {
    .st-header {
        height: auto;
        flex-direction: column;
        padding: 12px 16px;
        gap: 8px;
    }
    .st-nav { overflow-x: auto; width: 100%; justify-content: flex-start; }
    .st-header-right { display: none; }
    .fields-grid { grid-template-columns: 1fr 1fr; }
    .form-row-top { flex-direction: column; }
    .form-row-top .field-group { max-width: 100%; }
    .ctrl-bar { flex-direction: column; align-items: stretch; }
    .ch-row { flex-wrap: wrap; }
    .metric-row { grid-template-columns: 1fr 1fr; }
    .page-head { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
    .fields-grid { grid-template-columns: 1fr; }
    .metric-row  { grid-template-columns: 1fr; }
    .st-tab { padding: 6px 12px; font-size: 13px; }
}

/* ============================================================
   AUTH PAGES (Login / Sign Up)
   ============================================================ */
.stm-auth-page {
    margin: 0;
    padding: 0;
    
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-font-smoothing: antialiased;
}

.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    padding: 24px;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    max-width: 420px;
    width: 100%;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 32px;
    justify-content: center;
}
.auth-logo .st-logo-dot {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
}
.auth-logo .st-logo-dot svg { width: 20px; height: 20px; color: #fff; }

.auth-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 8px;
    text-align: center;
}

.auth-subtitle {
    color: var(--text-secondary);
    text-align: center;
    margin: 0 0 24px;
    font-size: 14px;
}

.auth-error {
    background: var(--danger-bg);
    color: var(--danger);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 13px;
    line-height: 1.5;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-form .field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.auth-form .field-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.auth-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    
    color: var(--text);
    background: var(--surface);
    transition: var(--transition);
    box-sizing: border-box;
}
.auth-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.12);
}

.auth-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.auth-remember {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.auth-btn {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: center;
    display: inline-block;
    text-decoration: none;
    background: var(--primary);
    color: #fff;
    transition: var(--transition);
}
.auth-btn:hover {
    background: var(--primary-hover);
}

.auth-footer-text {
    text-align: center;
    margin-top: 24px;
    font-size: 13px;
    color: var(--text-secondary);
}
.auth-footer-text a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.auth-footer-text a:hover {
    text-decoration: underline;
}
