/* ==========================================================================
   OrbiReach — Productive CRM Interface (v2)
   ClickUp-inspired clarity · Brand DNA preserved (Teal + Amber + Indigo)
   ========================================================================== */

:root {
    /* Brand */
    --primary: #7b68ee;
    --primary-hover: #6855dc;
    --primary-deep: #4f3fc4;
    --primary-soft: #efecff;
    --primary-ring: rgba(123, 104, 238, 0.26);

    --accent-pink: #ff4d97;
    --accent-blue: #3d8bfd;
    --accent-cyan: #22c1d6;
    --accent-green: #1fbf84;
    --accent-amber: #e8a93b;

    /* Workspace background (brand teal) */
    --bg: #2f7a7b;
    --bg-subtle: #2a6e6f;
    --bg-deep: #1f5556;

    /* Surfaces */
    --surface: #ffffff;
    --surface-2: #f7f6f2;
    --surface-3: #efece4;
    --surface-elevated: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.96);

    --border: #ece8de;
    --border-strong: #d9d3c4;
    --border-soft: #f1ede3;
    --glass-border: rgba(255, 255, 255, 0.55);

    /* Ink */
    --text: #19232a;
    --text-muted: #5b6b73;
    --text-soft: #8a98a0;
    --on-bg: #ffffff;
    --on-bg-muted: rgba(255, 255, 255, 0.78);

    /* Stages */
    --stage-0: #6b7a8a;
    --stage-1: #2563eb;
    --stage-2: #c98a16;
    --stage-3: #d96a1f;
    --stage-4: #16a07a;

    --success: #16a07a;
    --success-soft: #dff5ec;
    --danger: #e05656;
    --danger-soft: #fde7e7;
    --danger-hover: #c14444;
    --warning: #e8a93b;
    --warning-soft: #fff2cf;

    /* Geometry */
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;

    /* Elevation — softer, ClickUp-like */
    --shadow-xs: 0 1px 2px rgba(15, 35, 35, 0.05);
    --shadow-sm: 0 2px 6px rgba(15, 35, 35, 0.05), 0 1px 2px rgba(15, 35, 35, 0.04);
    --shadow:    0 6px 18px -8px rgba(15, 35, 35, 0.18), 0 2px 4px rgba(15, 35, 35, 0.04);
    --shadow-md: 0 16px 38px -18px rgba(15, 35, 35, 0.32), 0 4px 10px rgba(15, 35, 35, 0.05);
    --shadow-lg: 0 28px 70px -24px rgba(15, 35, 35, 0.45);

    --transition: 180ms cubic-bezier(0.22, 1, 0.36, 1);
    --transition-fast: 120ms cubic-bezier(0.22, 1, 0.36, 1);

    --sidebar-w: clamp(232px, 18vw, 264px);
    --content-max: 1480px;
}

/* ----- Base ----- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; scroll-behavior: smooth; }
body {
    min-height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background:
        radial-gradient(1100px 600px at 12% -10%, rgba(123,104,238,0.18), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, rgba(232,169,59,0.14), transparent 60%),
        linear-gradient(160deg, var(--bg) 0%, var(--bg-deep) 100%);
    background-attachment: fixed;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent 70%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }

/* ----- Layout ----- */
.app-container { display: flex; min-height: 100vh; width: 100%; }

/* ----- Sidebar ----- */
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    height: calc(100vh - 1.25rem);
    margin: 0.625rem 0 0.625rem 0.625rem;
    position: sticky;
    top: 0.625rem;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    padding: 1.05rem 0.95rem;
    background: var(--surface-glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(18px);
}
.logo {
    display: flex; align-items: center; gap: 0.7rem;
    padding: 0.4rem 0.5rem 0.85rem;
    border-bottom: 1px solid var(--border-soft);
}
.logo-icon {
    width: 36px; height: 36px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), var(--bg));
    box-shadow: 0 10px 22px -10px var(--primary-hover), inset 0 0 0 1px rgba(255,255,255,0.25);
    position: relative; flex: 0 0 auto;
}
.logo-icon::before, .logo-icon::after { content: ''; position: absolute; border-radius: 999px; }
.logo-icon::before { inset: 8px; border: 2px solid rgba(255,255,255,0.92); }
.logo-icon::after { width: 7px; height: 7px; right: 8px; top: 9px; background: var(--accent-amber); box-shadow: 0 0 8px rgba(232,169,59,0.6); }
.logo h2 { font-size: 1.04rem; font-weight: 800; letter-spacing: -0.025em; color: var(--text); }

.sidebar nav { display: grid; gap: 0.2rem; }
.nav-item {
    width: 100%;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    padding: 0.65rem 0.78rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    text-decoration: none;
    position: relative;
    transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}
.nav-item::before {
    content: '';
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--border-strong);
    flex: 0 0 auto;
    transition: inherit;
}
.nav-item:hover { background: rgba(123,104,238,0.07); color: var(--text); }
.nav-item:hover::before { background: var(--primary); }
.nav-item.active {
    background: linear-gradient(135deg, rgba(123,104,238,0.12), rgba(123,104,238,0.04));
    color: var(--primary-deep);
    font-weight: 700;
}
.nav-item.active::before {
    background: var(--primary);
    box-shadow: 0 0 0 4px rgba(123,104,238,0.18);
}
.nav-item.active::after {
    content: '';
    position: absolute;
    left: -0.95rem;
    top: 14%;
    bottom: 14%;
    width: 3px;
    border-radius: 0 4px 4px 0;
    background: linear-gradient(180deg, var(--primary), var(--accent-amber));
}

/* ----- Main ----- */
.main-content {
    flex: 1 1 auto;
    min-width: 0;
    padding: clamp(1rem, 2vw, 2rem);
    padding-bottom: 3rem;
    position: relative;
}
.page {
    display: none;
    width: min(100%, var(--content-max));
    margin-inline: auto;
    animation: fadeIn 240ms ease-out;
}
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes growUp { from { transform: scaleY(0); opacity: 0.4; } to { transform: scaleY(1); opacity: 1; } }
@keyframes pulseDot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(22,160,122,0.45); }
    50%      { box-shadow: 0 0 0 6px rgba(22,160,122,0); }
}

/* ----- Mobile menu ----- */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 0.75rem; left: 0.75rem;
    z-index: 70;
    width: 42px; height: 42px;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    background: var(--surface-elevated);
    color: var(--text);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}
.mobile-menu-toggle span, .mobile-menu-toggle span::before, .mobile-menu-toggle span::after {
    display: block; width: 18px; height: 2px; background: currentColor; border-radius: 3px; position: relative;
}
.mobile-menu-toggle span::before { content: ''; position: absolute; top: -6px; left: 0; }
.mobile-menu-toggle span::after  { content: ''; position: absolute; top: 6px;  left: 0; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,35,35,0.45); backdrop-filter: blur(3px); z-index: 49; opacity: 0; transition: opacity 180ms ease; }
.sidebar-backdrop.show { display: block; opacity: 1; }

/* ----- Page header ----- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: clamp(1.05rem, 1.8vw, 1.6rem);
    min-width: 0;
}
.page-header h1 {
    color: var(--on-bg);
    font-size: clamp(1.5rem, 2.3vw, 2.05rem);
    line-height: 1.1;
    font-weight: 800;
    letter-spacing: -0.035em;
    text-shadow: 0 1px 18px rgba(15,35,35,0.22);
}

/* ----- Surfaces ----- */
.glass-panel, .surface {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.glass-panel:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }

/* ----- Buttons ----- */
.btn {
    min-height: 36px;
    padding: 0.55rem 0.95rem;
    border-radius: 10px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.42rem;
    color: inherit;
    font-weight: 650;
    font-size: 0.86rem;
    line-height: 1.15;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible, .nav-item:focus-visible, .icon-btn:focus-visible, .tab-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-ring);
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #fff;
    box-shadow: 0 10px 22px -14px var(--primary-hover);
}
.btn-primary:hover { box-shadow: 0 14px 28px -14px var(--primary-hover); }
.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); border-color: #c4bca8; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: rgba(48,125,126,0.07); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(224,86,86,0.22); }
.btn-danger:hover { background: #fad8d8; border-color: rgba(224,86,86,0.36); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger-hover); }
.btn-small { min-height: 30px; padding: 0.4rem 0.65rem; border-radius: 8px; font-size: 0.78rem; }
.action-group { display: inline-flex; align-items: center; justify-content: flex-end; gap: 0.42rem; white-space: nowrap; }

/* ----- Stat cards ----- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(0.75rem, 1.4vw, 1.05rem);
    margin-bottom: clamp(1rem, 1.8vw, 1.5rem);
}
.stat-card {
    min-height: 124px;
    padding: clamp(1rem, 1.5vw, 1.25rem);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    position: relative;
    background: var(--surface);
}
.stat-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0;
    width: 4px; height: 100%;
    background: linear-gradient(180deg, var(--primary), var(--accent-amber));
    opacity: 0.85;
}
.stat-card::after {
    content: '';
    position: absolute;
    right: -30px; top: -30px;
    width: 110px; height: 110px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(123,104,238,0.12), transparent 67%);
    transition: transform var(--transition);
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card:hover::after { transform: scale(1.15); }
.stat-card:nth-child(2)::before { background: linear-gradient(180deg, var(--accent-blue), var(--accent-cyan)); }
.stat-card:nth-child(2)::after { background: radial-gradient(circle, rgba(61,139,253,0.14), transparent 67%); }
.stat-card:nth-child(3)::before { background: linear-gradient(180deg, var(--accent-amber), #f6ca72); }
.stat-card:nth-child(3)::after { background: radial-gradient(circle, rgba(232,169,59,0.16), transparent 67%); }
.stat-card:nth-child(4)::before { background: linear-gradient(180deg, var(--accent-green), #4fd1a3); }
.stat-card:nth-child(4)::after { background: radial-gradient(circle, rgba(31,191,132,0.14), transparent 67%); }
.stat-card h3 {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.09em;
}
.stat-value {
    color: var(--text);
    font-size: clamp(1.85rem, 3vw, 2.45rem);
    font-weight: 800;
    letter-spacing: -0.045em;
    line-height: 1;
    font-feature-settings: "tnum";
}

/* ----- Dashboard layout ----- */
.dashboard-grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
    gap: clamp(0.85rem, 1.4vw, 1.05rem);
}
.breakdown-card, .activity-card, .tasks-card {
    padding: clamp(1rem, 1.5vw, 1.25rem);
    min-width: 0;
    background: var(--surface);
}
.tasks-card { margin-bottom: clamp(1rem, 1.8vw, 1.5rem); }
.tasks-card #dash-today-emails-helper { margin: -0.25rem 0 0.9rem; font-size: 0.82rem; }

/* ----- Analytics card ----- */
.analytics-card {
    background:
        radial-gradient(800px 300px at 100% -20%, rgba(123,104,238,0.08), transparent 70%),
        var(--surface);
}
.analytics-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.analytics-kpi {
    border: 1px solid var(--border);
    background: linear-gradient(180deg, #fbfaf6, #f5f2e8);
    border-radius: var(--radius);
    padding: 0.85rem 0.95rem;
    position: relative;
    overflow: hidden;
}
.analytics-kpi::after {
    content: '';
    position: absolute;
    right: -20px; bottom: -25px;
    width: 80px; height: 80px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(123,104,238,0.18), transparent 70%);
}
.analytics-kpi:nth-child(2)::after { background: radial-gradient(circle, rgba(232,169,59,0.22), transparent 70%); }
.analytics-kpi-label {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.analytics-kpi-value {
    color: var(--primary-deep);
    font-size: 1.7rem;
    font-weight: 800;
    line-height: 1.1;
    margin-top: 0.25rem;
    letter-spacing: -0.03em;
    font-feature-settings: "tnum";
}
.analytics-kpi:nth-child(2) .analytics-kpi-value { color: #8a5a10; }
.analytics-kpi-sub { color: var(--text-muted); font-size: 0.78rem; margin-top: 0.3rem; font-weight: 600; }

.analytics-charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
}
.analytics-title {
    font-size: 0.82rem;
    color: var(--text);
    margin-bottom: 0.5rem;
    font-weight: 750;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.analytics-title::before {
    content: '';
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--primary);
}
.analytics-charts-grid > div:nth-child(2) .analytics-title::before { background: var(--accent-amber); }

/* ----- Mini chart (improved) ----- */
.mini-chart {
    min-height: 150px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background:
        linear-gradient(180deg, #ffffff, #fafaf6);
    padding: 0.85rem 0.55rem 0.45rem;
    display: flex;
    align-items: flex-end;
    gap: 0.32rem;
    overflow-x: auto;
    position: relative;
}
.mini-chart::before,
.mini-chart::after {
    content: '';
    position: absolute;
    left: 0; right: 0;
    height: 1px;
    background: rgba(15,35,35,0.06);
    pointer-events: none;
}
.mini-chart::before { top: 33%; }
.mini-chart::after  { top: 66%; }
.mini-chart-bar {
    min-width: 22px;
    flex: 1 1 22px;
    border-radius: 6px 6px 3px 3px;
    background: linear-gradient(180deg, var(--primary) 0%, var(--accent-blue) 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 0.22rem;
    box-shadow: 0 6px 14px -10px rgba(123,104,238,0.7);
    transform-origin: bottom;
    animation: growUp 420ms cubic-bezier(0.22, 1, 0.36, 1);
    cursor: default;
    position: relative;
    transition: filter var(--transition-fast), transform var(--transition-fast);
}
.mini-chart-bar:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}
.mini-chart-bar.is-zero {
    background: repeating-linear-gradient(45deg, #ece8de, #ece8de 4px, #f5f1e6 4px, #f5f1e6 8px);
    box-shadow: none;
}
.mini-chart-bar.is-today {
    background: linear-gradient(180deg, var(--accent-amber) 0%, #f6ca72 100%);
    box-shadow: 0 8px 18px -10px rgba(232,169,59,0.85);
}
.mini-chart-value {
    color: #fff;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.18rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.18);
    font-feature-settings: "tnum";
}
.mini-chart-bar.is-zero .mini-chart-value { color: var(--text-soft); text-shadow: none; }
.mini-chart-label {
    position: absolute;
    bottom: -1.05rem;
    color: var(--text-muted);
    font-size: 0.6rem;
    font-weight: 650;
    line-height: 1;
    white-space: nowrap;
    font-feature-settings: "tnum";
}
.mini-chart { padding-bottom: 1.55rem; }

/* ----- Panel headings ----- */
.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.85rem;
    margin-bottom: 1rem;
}
.panel-heading h3, .breakdown-card h3, .activity-card h3 {
    font-size: 0.96rem;
    color: var(--text);
    font-weight: 750;
    letter-spacing: -0.012em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.panel-heading h3::before, .breakdown-card h3::before, .activity-card h3::before {
    content: '';
    width: 4px; height: 16px;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--primary), var(--accent-amber));
}
.breakdown-card h3, .activity-card h3 {
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.85rem;
    margin-bottom: 1rem;
}

/* ----- Lists ----- */
.breakdown-list, .activity-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    min-width: 0;
}
.breakdown-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 0.78rem;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 0.9rem;
    transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}
.breakdown-list li:hover {
    background: var(--surface-2);
    border-color: var(--border);
    transform: translateX(2px);
}
.breakdown-metric { display: inline-flex; align-items: center; gap: 0.75rem; }
.breakdown-percent { color: var(--text-muted); font-size: 0.82rem; font-weight: 650; font-feature-settings: "tnum"; }
.breakdown-list li strong { font-feature-settings: "tnum"; font-weight: 750; }

.activity-list li, .task-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.78rem 0.86rem;
    color: var(--text);
    min-width: 0;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}
.activity-list li:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.outbox-item { cursor: pointer; }
.outbox-item:hover { transform: translateY(-1px); }
.activity-time {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 650;
    margin-bottom: 0.3rem;
    font-feature-settings: "tnum";
}
.activity-time::before {
    content: '';
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--primary);
    animation: pulseDot 2.4s ease-out infinite;
}
.activity-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; min-width: 0; }
.activity-main, .contact-cell, .task-main { min-width: 0; overflow-wrap: anywhere; }
.muted { color: var(--text-muted); }
.empty-note {
    color: var(--text-muted);
    padding: 1.4rem 1rem;
    text-align: center;
    font-weight: 600;
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: 10px;
}

/* ----- Task cards ----- */
.task-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    border-left: 3px solid var(--primary);
    transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.task-item:hover {
    transform: translateX(3px);
    border-left-color: var(--accent-amber);
    box-shadow: var(--shadow-sm);
}
.task-title { display: inline-flex; align-items: center; min-width: 0; max-width: 100%; gap: 0.2rem; }
.task-title strong { font-weight: 700; }
.task-company { color: var(--text-muted); font-size: 0.86rem; }
.task-due {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--stage-2);
    font-size: 0.8rem;
    font-weight: 650;
    margin-top: 0.3rem;
    background: var(--warning-soft);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
}
.task-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* ----- Tables ----- */
.table-container {
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    background: var(--surface);
}
table { width: 100%; min-width: 700px; border-collapse: separate; border-spacing: 0; }
th, td { padding: 0.88rem 1rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
    position: sticky; top: 0; z-index: 1;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
td { color: var(--text); font-size: 0.88rem; }
tbody tr { transition: background var(--transition-fast); }
tbody tr:hover { background: rgba(123,104,238,0.04); }
tbody tr:last-child td { border-bottom: 0; }
#emails-table { min-width: 900px; }
#emails-table th:first-child, #emails-table td:first-child { min-width: 245px; }
#emails-table th:last-child, #emails-table td:last-child { width: 230px; }
.actions-narrow { width: 140px; }
.actions-wide { width: 220px; }

/* ----- Badges ----- */
.stage-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1.35;
    white-space: nowrap;
    border: 1px solid transparent;
}
.stage-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.stage-badge-0 { background: #eef2f6; color: var(--stage-0); border-color: #e3e9ef; }
.stage-badge-1 { background: #dbeafe; color: #1d4ed8; border-color: #c7dcfd; }
.stage-badge-2 { background: var(--warning-soft); color: #a66d0f; border-color: #ffe39d; }
.stage-badge-3 { background: #ffeadb; color: #c25614; border-color: #ffd7bc; }
.stage-badge-4 { background: var(--success-soft); color: #087458; border-color: #c5ecda; }
.stage-text-0 { color: var(--stage-0); font-weight: 700; }
.stage-text-1 { color: var(--stage-1); font-weight: 700; }
.stage-text-2 { color: var(--stage-2); font-weight: 700; }
.stage-text-3 { color: var(--stage-3); font-weight: 700; }
.stage-text-4 { color: var(--stage-4); font-weight: 700; }

.niche-tag {
    display: inline-flex;
    align-items: center;
    max-width: 180px;
    padding: 0.25rem 0.62rem;
    background: var(--primary-soft);
    color: var(--primary-deep);
    border: 1px solid rgba(123,104,238,0.18);
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.content-dot {
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--success);
    margin-left: 5px;
    vertical-align: middle;
    box-shadow: 0 0 0 3px rgba(22,160,122,0.14);
}

/* ----- Forms ----- */
.form-group { margin-bottom: 1rem; min-width: 0; }
.form-group label, .field-label {
    display: block;
    margin-bottom: 0.42rem;
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 700;
}
.label-muted { color: var(--text-muted); font-size: 0.78rem; font-weight: 600; }
input, select, textarea {
    width: 100%;
    min-width: 0;
    padding: 0.62rem 0.78rem;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text);
    font-size: 0.88rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
input::placeholder, textarea::placeholder { color: var(--text-soft); }
input:hover, select:hover, textarea:hover { border-color: #b8b09a; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
    background: var(--surface);
}
textarea { resize: vertical; min-height: 112px; line-height: 1.55; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.85rem; }
.form-row .form-group { margin-bottom: 1rem; }
.form-field-wide { grid-column: span 1; }
.required { color: var(--danger); margin-left: 2px; }
.filters {
    padding: 0.86rem;
    margin-bottom: 1rem;
    display: grid;
    grid-template-columns: minmax(170px, 230px) minmax(220px, 1fr);
    gap: 0.65rem;
    align-items: center;
    background: var(--surface);
}

/* ----- Daily tracker widget ----- */
.daily-tracker-widget {
    min-width: min(100%, 268px);
    padding: 0.95rem 1.1rem;
    display: grid;
    gap: 0.55rem;
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 650;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.daily-tracker-widget > div:first-child {
    display: flex; align-items: center; gap: 0.4rem;
    color: var(--text);
    font-weight: 700;
}
.daily-tracker-widget span { color: var(--primary-deep); font-weight: 800; font-feature-settings: "tnum"; }
.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--surface-3);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}
.progress-bar {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), var(--accent-amber));
    box-shadow: 0 0 14px rgba(232,169,59,0.32);
    transition: width 600ms cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
    overflow: hidden;
}
.progress-bar::after {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.45), transparent);
    transform: translateX(-100%);
    animation: shimmer 2.4s ease-in-out infinite;
}
@keyframes shimmer { 50%, 100% { transform: translateX(100%); } }

/* ----- Templates ----- */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(0.85rem, 1.4vw, 1.05rem);
}
.template-card {
    padding: clamp(1rem, 1.6vw, 1.3rem);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-width: 0;
    background: var(--surface);
}
.template-card:hover { transform: translateY(-2px); }
.template-card h3 {
    color: var(--text);
    font-size: 1rem;
    font-weight: 750;
    letter-spacing: -0.012em;
    text-transform: capitalize;
}
.template-subject { margin-top: 0.25rem; font-weight: 700; overflow-wrap: anywhere; }
.template-body-preview {
    font-size: 0.82rem;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 0.85rem;
    border-radius: 10px;
    white-space: pre-wrap;
    min-height: 112px;
    max-height: 220px;
    overflow: auto;
    line-height: 1.55;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    overflow-wrap: anywhere;
}
.template-card .btn { margin-top: auto; }

/* ----- Stage selector ----- */
.stage-select {
    min-width: 138px;
    padding: 0.4rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 650;
    cursor: pointer;
    background: var(--surface);
    border: 1px solid var(--border-strong);
}
.icon-btn {
    width: 28px; height: 28px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    vertical-align: middle;
    margin-left: 0.25rem;
    flex: 0 0 auto;
    transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}
.icon-btn:hover {
    background: var(--primary-soft);
    color: var(--primary-deep);
    transform: translateY(-1px);
}

/* ----- Modal ----- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,35,35,0.5);
    backdrop-filter: blur(6px);
    z-index: 100;
    display: none;
    opacity: 0;
    transition: opacity 200ms ease;
}
.modal-overlay.show { display: block; opacity: 1; }
.modal {
    position: fixed;
    top: 50%; left: 50%;
    width: min(100% - 2rem, 500px);
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding: 1.5rem;
    z-index: 101;
    display: none;
    opacity: 0;
    transform: translate(-50%, -47%) scale(0.97);
    transition: opacity 200ms ease, transform 200ms ease;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.modal.show { display: block; opacity: 1; transform: translate(-50%, -50%) scale(1); }
.modal h2 {
    font-size: 1.14rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 1.2rem;
    letter-spacing: -0.018em;
}
.modal-subtitle { margin-bottom: 1.5rem; font-size: 0.9rem; }
.modal-wide { width: min(100% - 2rem, 760px); }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.6rem;
    margin-top: 1.4rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.confirm-dialog { max-width: 430px; }
.confirm-dialog .confirm-icon {
    width: 46px; height: 46px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 800;
    margin-bottom: 0.9rem;
}
.confirm-dialog .confirm-icon.danger  { background: var(--danger-soft); color: var(--danger); }
.confirm-dialog .confirm-icon.warning { background: var(--warning-soft); color: #a66d0f; }
.confirm-dialog .confirm-icon.info    { background: var(--primary-soft); color: var(--primary-deep); }
.confirm-dialog h3 { font-size: 1.06rem; font-weight: 800; margin-bottom: 0.45rem; }
.confirm-dialog p { color: var(--text-muted); line-height: 1.55; }

/* ----- Tabs ----- */
.tab-bar {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 1.2rem;
    padding: 0.3rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow-x: auto;
}
.tab-btn {
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text-muted);
    padding: 0.55rem 0.95rem;
    font-weight: 700;
    font-size: 0.84rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    background: var(--surface);
    color: var(--primary-deep);
    box-shadow: var(--shadow-xs);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 180ms ease-out; }

/* ----- Toast ----- */
.toast {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    max-width: calc(100vw - 2.5rem);
    padding: 0.85rem 1.05rem;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 220ms ease, transform 220ms ease;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 650;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex: 0 0 auto; }
.toast-success { border-left-color: var(--success); } .toast-success::before { background: var(--success); }
.toast-error   { border-left-color: var(--danger);  } .toast-error::before   { background: var(--danger); }
.toast-info    { border-left-color: var(--primary); }
.empty-state { text-align: center; color: var(--text-muted); padding: 2.5rem 1rem; font-weight: 600; }

/* ----- Scrollbar ----- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(196,188,168,0.7);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(167,159,140,0.9);
    background-clip: padding-box;
}

/* ----- Responsive ----- */
@media (max-width: 1240px) {
    :root { --sidebar-w: 224px; }
    .main-content { padding: 1.15rem; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .templates-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid-2 { grid-template-columns: 1fr; }
    th, td { padding-inline: 0.82rem; }
}
@media (max-width: 980px) {
    .mobile-menu-toggle { display: inline-flex; }
    .sidebar {
        position: fixed; top: 0; left: 0;
        height: 100vh;
        margin: 0;
        border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
        transform: translateX(-104%);
        transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { padding: 4rem 1rem 2rem; }
    .page-header { align-items: flex-start; }
}
@media (max-width: 720px) {
    body { font-size: 13.5px; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .btn, .daily-tracker-widget { width: 100%; }
    .stats-grid, .templates-grid { grid-template-columns: 1fr; }
    .filters { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; gap: 0; }
    .modal { width: calc(100% - 1rem); padding: 1.1rem; }
    .modal-actions { flex-direction: column-reverse; }
    .modal-actions .btn { width: 100%; }
    .task-item, .activity-row { align-items: flex-start; }
    .task-actions { width: 100%; }
    .task-actions .stage-select, .task-actions .btn { flex: 1 1 150px; }
    .analytics-summary-grid, .analytics-charts-grid { grid-template-columns: 1fr; }
    .toast { left: 1rem; right: 1rem; bottom: 1rem; max-width: none; }
}
@media (max-width: 440px) {
    .main-content { padding-inline: 0.75rem; }
    .stat-card { min-height: 112px; }
    .action-group { flex-wrap: wrap; justify-content: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
