/*
 * KD Command — Application Styles (Facelift "1a Refined")
 *
 * Drop-in replacement for assets/css/app.css.
 * Same selectors and layout metrics as the original — visual restyle only.
 * All colors reference CSS custom properties set by theme.php.
 */

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

html, body { overflow-x: hidden; }

body {
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(var(--color-accent-rgb), 0.25); }

/* Subtle scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--color-secondary); background-clip: content-box; }

a { color: var(--color-accent); text-decoration: none; transition: color 0.15s; }
a:hover { color: #f7b45c; }

h1, h2, h3, h4 { font-family: var(--font-heading); font-weight: 700; color: var(--color-text); letter-spacing: -0.01em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 0.975rem; }

img { max-width: 100%; }

/* ── Layout ───────────────────────────────────────────────── */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 24px 40px;
}

.container-full { padding: 22px 26px; }

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

.page-header h1 { margin: 0; }

/* ── App Layout (Sidebar + Main) ──────────────────────────── */
.app-layout {
    display: flex;
    min-height: calc(100vh - 48px - 42px);
    margin-top: 48px;
    margin-bottom: 42px;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: 240px;
    background: var(--color-primary);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 48px;
    left: 0;
    bottom: 42px;
    z-index: 150;
    transition: width 0.2s ease;
    overflow: hidden;
}

.sidebar.collapsed { width: 60px; }

.sidebar-section-label {
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--color-text-dim, rgba(255,255,255,0.35));
    padding: 20px 18px 6px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.15s;
}

.sidebar.collapsed .sidebar-section-label {
    opacity: 0;
    height: 12px;
    padding: 6px 0 0;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
    position: relative;
}

.sidebar-link svg {
    flex-shrink: 0;
    width: 15px;
    height: 15px;
}

.sidebar-link:hover {
    color: var(--color-text);
    background: var(--tint-05);
}

.sidebar-link.active {
    color: var(--color-accent);
    background: rgba(var(--color-accent-rgb), 0.1);
    font-weight: 600;
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 2px;
    border-radius: 0 2px 2px 0;
    background: var(--color-accent);
}

.sidebar-link-text { transition: opacity 0.15s; }

.sidebar.collapsed .sidebar-link { justify-content: center; padding: 9px 0; }
.sidebar.collapsed .sidebar-link-text { opacity: 0; width: 0; overflow: hidden; }
.sidebar.collapsed .sidebar-link.active::before { left: 0; }

.sidebar.collapsed .sidebar-link:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 56px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--color-surface);
    color: var(--color-text);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8125rem;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    border: 1px solid var(--color-border);
    z-index: 200;
    pointer-events: none;
}

/* ── Main Content ────────────────────────────────────────── */
.app-main {
    flex: 1;
    margin-left: 240px;
    width: calc(100% - 240px);
    max-width: calc(100vw - 240px);
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 48px - 42px);
    transition: margin-left 0.2s ease, width 0.2s ease, max-width 0.2s ease;
    overflow-x: hidden;
    background: var(--color-bg);
}

.sidebar.collapsed ~ .app-main {
    margin-left: 60px;
    width: calc(100% - 60px);
    max-width: calc(100vw - 60px);
}

/* ── Top Bar ─────────────────────────────────────────────── */
.topbar {
    height: 48px;
    background: var(--color-primary);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--color-text);
    white-space: nowrap;
}

.topbar-brand-logo { height: 24px; width: auto; }

.topbar-brand-text {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color 0.15s ease;
}

.topbar-brand:hover .topbar-brand-text { color: var(--color-accent); }

.topbar-hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    margin-right: 12px;
}

.topbar-hamburger:hover { color: var(--color-text); background: var(--tint-06); }

.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.topbar-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    position: relative;
}

.topbar-icon-btn:hover { color: var(--color-text); background: var(--tint-06); }

.topbar-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--color-accent);
    color: var(--color-primary);
    font-size: 0.625rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    border-radius: 8px;
    padding: 0 4px;
    font-variant-numeric: tabular-nums;
}

/* ── Notification Dropdown ───────────────────────────────── */
.notif-wrapper { position: relative; }

.notif-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 380px;
    max-height: 480px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.notif-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: 0.875rem;
}

.notif-mark-all {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--color-accent);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
    font-family: inherit;
}
.notif-mark-all:hover { background: rgba(var(--color-accent-rgb), 0.1); }

.notif-list { overflow-y: auto; flex: 1; max-height: 420px; }

.notif-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.8125rem;
}

.notif-item {
    display: flex;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border-soft, var(--color-border));
    cursor: pointer;
    transition: background 0.12s;
    text-decoration: none;
    color: inherit;
    position: relative;
}
.notif-item:hover { background: var(--tint-03); }
.notif-item.unread { background: rgba(var(--color-accent-rgb), 0.05); }
.notif-item.unread::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--color-accent);
}

.notif-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
}
.notif-icon.email-open  { background: rgba(127,168,201,0.13); color: var(--color-info); }
.notif-icon.email-click { background: rgba(79,191,139,0.13); color: var(--color-success); }
.notif-icon.page-view   { background: rgba(var(--color-accent-rgb),0.13); color: var(--color-accent); }
.notif-icon.went-hot    { background: rgba(232,95,92,0.13); color: var(--color-danger); }
.notif-icon.research    { background: rgba(212,149,42,0.13); color: var(--color-warning); }
.notif-icon.email-draft { background: rgba(127,168,201,0.13); color: var(--color-info); }
.notif-icon.linkedin    { background: rgba(127,168,201,0.13); color: var(--color-info); }
.notif-icon.default     { background: var(--tint-06); color: var(--color-text-muted); }

.notif-body { flex: 1; min-width: 0; }

.notif-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
    margin-bottom: 2px;
}

.notif-desc {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notif-time {
    flex-shrink: 0;
    font-size: 0.6875rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    padding-top: 2px;
}

.topbar-divider {
    width: 1px;
    height: 24px;
    background: var(--color-border);
    margin: 0 4px;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-text);
    font-size: 0.8125rem;
}

.topbar-user strong { font-weight: 600; }

.topbar-logout {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    text-decoration: none;
    padding: 3px 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    transition: all 0.15s;
}

.topbar-logout:hover { color: var(--color-text); border-color: var(--color-secondary); }

.producer-switcher {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 7px;
    padding: 5px 10px;
    font-size: 0.8125rem;
    cursor: pointer;
    font-family: inherit;
}

.producer-switcher option { color: var(--color-text); background: var(--color-surface); }

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 18px 20px;
    margin-bottom: 14px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 15px;
    font-size: 0.8125rem;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.4;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-accent), var(--color-accent-2, var(--color-accent)));
    color: var(--color-primary);
    font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.1); color: var(--color-primary); }

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text-secondary, var(--color-text));
    border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-surface-2, var(--color-bg)); border-color: var(--color-secondary); color: var(--color-text); }

.btn-success { background: var(--color-success); color: var(--color-primary); font-weight: 700; }
.btn-success:hover { filter: brightness(1.1); }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.btn-sm { padding: 4px 10px; font-size: 0.78125rem; border-radius: 7px; }

.btn-icon {
    padding: 6px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: 6px;
}
.btn-icon:hover { background: var(--tint-05); color: var(--color-text); }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

.form-group label {
    display: block;
    font-size: 0.78125rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    font-family: inherit;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(var(--color-accent-rgb), 0.15);
}

select.form-control { cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.form-actions { display: flex; gap: 8px; margin-top: 20px; }

.inline-edit {
    border: 1px solid transparent;
    padding: 4px 8px;
    border-radius: 6px;
    background: transparent;
    font-size: inherit;
    color: inherit;
    font-family: inherit;
    width: 100%;
}

.inline-edit:hover { border-color: var(--color-border); }
.inline-edit:focus {
    border-color: var(--color-accent);
    outline: none;
    background: var(--color-bg);
}

/* ── Tables ───────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.data-table th {
    text-align: left;
    font-size: 0.65625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-dim, var(--color-text-muted));
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    cursor: pointer;
}

.data-table th:hover { color: var(--color-text); }

.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border-soft, var(--color-border));
    font-size: 0.8125rem;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--tint-025); }
.data-table .clickable-row { cursor: pointer; }

/* ── Badges / Pills ───────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.71875rem;
    font-weight: 600;
    border-radius: 6px;
    line-height: 1.45;
}

/* Stage badges keep their per-stage inline background (solid) */
.badge-stage { color: #fff; }

/* Semantic badges are tinted, not solid — quieter tables */
.badge-success { background: rgba(79,191,139,0.13);  color: var(--color-success); }
.badge-danger  { background: rgba(232,95,92,0.13);   color: var(--color-danger); }
.badge-warning { background: rgba(212,149,42,0.13);  color: var(--color-warning); }
.badge-info    { background: rgba(127,168,201,0.13); color: var(--color-info); }
.badge-muted   { background: var(--tint-06); color: var(--color-text-muted); }

/* Heat badges (prospects) */
.badge-hot  { background: rgba(232,95,92,0.12);  color: var(--color-danger);  font-weight: 700; }
.badge-warm { background: rgba(212,149,42,0.12); color: var(--color-warning); font-weight: 700; }
.badge-cold { background: var(--tint-05); color: var(--color-text-dim, var(--color-text-muted)); }

/* ── Pipeline / Kanban ────────────────────────────────────── */
.pipeline-board {
    display: flex;
    gap: 8px;
    padding-bottom: 16px;
    height: calc(100vh - 140px);
    align-items: stretch;
}

.pipeline-column {
    flex: 1 1 0;
    min-width: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    transition: flex 0.25s ease, min-width 0.25s ease;
    overflow: hidden;
}

.pipeline-column.collapsed {
    flex: 0 0 36px;
    min-width: 36px;
    max-width: 36px;
    cursor: pointer;
}

.pipeline-column.collapsed .pipeline-column-body,
.pipeline-column.collapsed .pipeline-column-footer,
.pipeline-column.collapsed .pipeline-column-header .pipeline-column-title > span:not(.collapse-label),
.pipeline-column.collapsed .pipeline-column-header .pipeline-column-count {
    display: none;
}

.pipeline-column.collapsed .pipeline-column-header {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    padding: 12px 6px;
    border-bottom: none;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.pipeline-column.collapsed .pipeline-column-title {
    white-space: nowrap;
    font-size: 0.71875rem;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.pipeline-column.collapsed .collapse-label { display: inline; }

.collapse-toggle {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 0.75rem;
    line-height: 1;
    border-radius: 4px;
    margin-left: auto;
    flex-shrink: 0;
}

.collapse-toggle:hover,
.expand-toggle:hover {
    color: var(--color-text);
    background: var(--tint-06);
}

.expand-toggle {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 0.75rem;
    line-height: 1;
    border-radius: 4px;
}

.pipeline-column .expand-toggle { display: none; }
.pipeline-column.collapsed .collapse-toggle { display: none; }
.pipeline-column.collapsed .expand-toggle {
    display: block;
    writing-mode: horizontal-tb;
    margin: 12px auto 0;
    font-size: 1rem;
    padding: 4px 8px;
}

.pipeline-column-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    border-radius: 10px 10px 0 0;
    background: inherit;
    flex-shrink: 0;
}

.pipeline-column-title {
    font-size: 0.78125rem;
    font-weight: 700;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.pipeline-column-count {
    background: var(--tint-06);
    color: var(--color-text-muted);
    font-size: 0.6875rem;
    padding: 1px 8px;
    border-radius: 9px;
    font-variant-numeric: tabular-nums;
}

.pipeline-column-body {
    padding: 8px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    background: var(--color-bg);
}

.pipeline-column-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--color-border);
    font-size: 0.6875rem;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border-radius: 0 0 10px 10px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.deal-card {
    background: var(--color-surface-2, var(--color-surface));
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 8px 11px;
    margin-bottom: 7px;
    cursor: grab;
    transition: box-shadow 0.15s, border-color 0.15s;
    position: relative;
}

.deal-card:hover {
    box-shadow: 0 3px 14px rgba(0,0,0,0.35);
    border-color: var(--color-secondary);
}

.deal-card.sortable-ghost { opacity: 0.4; }
.deal-card.sortable-chosen { box-shadow: 0 6px 20px rgba(0,0,0,0.45); }

.deal-card-title {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-text);
    margin-bottom: 3px;
    line-height: 1.25;
}

.deal-card-title a { color: inherit; text-decoration: none; }
.deal-card-title a:hover { color: var(--color-accent); }

.deal-card-sub {
    font-weight: 600;
    font-size: 0.71875rem;
    color: var(--color-text-secondary, var(--color-text));
    line-height: 1.3;
    margin-bottom: 1px;
    font-variant-numeric: tabular-nums;
}

.deal-card-line3 {
    font-size: 0.65625rem;
    color: var(--color-text-muted);
    line-height: 1.3;
}

.deal-card-meta {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.deal-card-amount {
    font-weight: 600;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.deal-card-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    border-radius: 8px 0 0 8px;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 20px;
}

.tab {
    padding: 9px 16px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}

.tab:hover { color: var(--color-text); }

.tab.active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
    font-weight: 700;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Activity Timeline ────────────────────────────────────── */
.timeline { position: relative; padding-left: 24px; }

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--color-border);
}

.timeline-item { position: relative; padding-bottom: 16px; }

.timeline-dot {
    position: absolute;
    left: -20px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-border);
    border: 2px solid var(--color-surface);
}

.timeline-dot.email-open   { background: var(--color-info); }
.timeline-dot.email-click  { background: var(--color-success); }
.timeline-dot.page-view    { background: var(--color-accent); }
.timeline-dot.note         { background: var(--color-text-muted); }
.timeline-dot.stage-change { background: var(--color-secondary); }
/* Hand-logged activity (Log Activity). Warm family, because these are things a
   producer DID — as against the cool info/success dots, which are things a
   prospect did. 'logged-email' is not called 'email': that would sit one
   keystroke from the email-open / email-click event colours above, which is
   the confusion the timeline wording is already working to prevent. */
.timeline-dot.call         { background: var(--color-warning); }
.timeline-dot.logged-email { background: var(--color-accent-2); }
.timeline-dot.other        { background: var(--color-text-dim); }

/* ── Stats Cards ──────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 14px 16px;
}

.stat-card-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.stat-card-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.stat-card-sub {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* ── Flash Messages ───────────────────────────────────────── */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.875rem;
}

.flash-success { background: rgba(79,191,139,0.12); color: #7fd4ab; border: 1px solid rgba(79,191,139,0.3); }
.flash-error,
.flash-danger  { background: rgba(232,95,92,0.12); color: #f5908e; border: 1px solid rgba(232,95,92,0.3); }
.flash-warning { background: rgba(212,149,42,0.12); color: #e8b44d; border: 1px solid rgba(212,149,42,0.3); }
.flash-info    { background: rgba(127,168,201,0.12); color: #a9c8e0; border: 1px solid rgba(127,168,201,0.3); }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(6,7,9,0.7);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 24px 70px rgba(0,0,0,0.55);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
}

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

.modal-header h3 { margin: 0; }

.modal-body { padding: 20px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
}

/* ── Pagination ───────────────────────────────────────────── */
.pagination {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-top: 20px;
    justify-content: center;
}

.pagination a, .pagination span {
    padding: 6px 12px;
    font-size: 0.8125rem;
    border: 1px solid var(--color-border);
    border-radius: 7px;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.pagination a:hover { background: var(--tint-04); color: var(--color-text); }

.pagination .current {
    background: var(--color-accent);
    color: var(--color-primary);
    border-color: var(--color-accent);
    font-weight: 700;
}

/* ── Search & Filters Bar ─────────────────────────────────── */
.filters-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.8125rem;
    background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%237a8290' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.656a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 12px center;
    font-family: inherit;
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(var(--color-accent-rgb), 0.12);
}

.filter-select {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.8125rem;
    background: var(--color-surface);
    color: var(--color-text-secondary, var(--color-text));
    cursor: pointer;
    font-family: inherit;
}

/* ── Login Page ───────────────────────────────────────────── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(700px 400px at 70% -10%, rgba(var(--color-accent-rgb), 0.06), transparent 70%),
        var(--color-bg);
}

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 14px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 24px 70px rgba(0,0,0,0.45);
}

.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo img { height: 40px; }

.login-title {
    text-align: center;
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin-bottom: 24px;
}

.login-error {
    background: rgba(232,95,92,0.12);
    color: #f5908e;
    border: 1px solid rgba(232,95,92,0.3);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 16px;
}

/* ── Bottom Bar ───────────────────────────────────────────── */
.bottombar {
    height: 42px;
    background: var(--color-primary);
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
}

.bottombar-left { flex: 0 0 auto; display: flex; align-items: center; }

.bottombar-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bottombar-right { flex: 0 0 auto; width: 42px; }

.bottombar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    transition: opacity 0.2s;
}

.bottombar-brand:hover { opacity: 0.8; }

.bottombar-logo { height: 22px; width: auto; opacity: 0.7; }

.bottombar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
}

.bottombar-collapse-btn:hover { color: var(--color-text); background: var(--tint-06); }

.bottombar-collapse-btn .expand-icon { display: none; }
.sidebar.collapsed ~ .app-main ~ .bottombar .collapse-icon,
body.sidebar-collapsed .bottombar .collapse-icon { display: none; }
.sidebar.collapsed ~ .app-main ~ .bottombar .expand-icon,
body.sidebar-collapsed .bottombar .expand-icon { display: block; }

/* ── Utility ──────────────────────────────────────────────── */
.text-muted { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 600; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none; }
.w-full { width: 100%; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1024px) {
    .sidebar { width: 60px; }
    .sidebar .sidebar-section-label { opacity: 0; height: 12px; padding: 6px 0 0; }
    .sidebar .sidebar-link { justify-content: center; padding: 9px 0; }
    .sidebar .sidebar-link-text { opacity: 0; width: 0; overflow: hidden; }
    .sidebar .sidebar-link.active::before { left: 0; }
    .app-main { margin-left: 60px; width: calc(100% - 60px); max-width: calc(100vw - 60px); }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: 240px; }
    .sidebar.mobile-open { transform: translateX(0); }
    .app-main { margin-left: 0; width: 100%; max-width: 100vw; }
    .topbar-hamburger { display: flex; }
    .bottombar-collapse-btn { display: none; }
    .form-row { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .pipeline-board { overflow-x: auto; }
    .pipeline-column { flex: 0 0 85vw; min-width: 85vw; }
    .container { padding: 16px 12px; }
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 140;
}

.sidebar-overlay.open { display: block; }

/* ── Light/dark toggle icon swap ─────────────────────────── */
html[data-theme="light"] .kd-icon-moon { display: none; }
html[data-theme="light"] .kd-icon-sun  { display: inline !important; }
