/* ==========================================================================
   Portal Layout
   ========================================================================== */

/* ---------- Shell ---------- */

.portal-shell {
    display: flex;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
    width: 240px;
    background: var(--ds-surface);
    border-right: 1px solid var(--ds-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--ds-space-sm);
    padding: var(--ds-space-lg);
    border-bottom: 1px solid var(--ds-border);
}

.sidebar-brand h2 {
    margin: 0;
    font-size: 1.125rem;
    color: var(--ds-primary);
}

.sidebar-nav {
    flex: 1;
    padding: var(--ds-space-sm) 0;
}

.nav-section {
    padding: var(--ds-space-xs) var(--ds-space-lg);
    margin-top: var(--ds-space-sm);
}

.nav-section-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ds-text-muted);
    margin-bottom: var(--ds-space-xs);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--ds-space-sm);
    padding: 0.5rem var(--ds-space-lg);
    color: var(--ds-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0;
    transition: color 0.15s, background-color 0.15s;
    text-decoration: none;
    cursor: pointer;
}

.nav-item:hover {
    color: var(--ds-text);
    background-color: var(--ds-bg);
    text-decoration: none;
}

.nav-item.active {
    color: var(--ds-primary);
    background-color: rgba(196, 101, 46, 0.08);
    font-weight: 600;
}

.nav-item .nav-icon {
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: var(--ds-space-md) var(--ds-space-lg);
    border-top: 1px solid var(--ds-border);
    font-size: 0.8125rem;
    color: var(--ds-text-muted);
}

.sidebar-footer .user-name {
    font-weight: 600;
    color: var(--ds-text);
}

/* ---------- Main Content ---------- */

.main-content {
    flex: 1;
    margin-left: 240px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--ds-space-lg) var(--ds-space-2xl);
    border-bottom: 1px solid var(--ds-border);
    background: var(--ds-surface);
}

.page-header h1 {
    margin: 0;
    font-size: 1.5rem;
}

.page-header p {
    margin: var(--ds-space-xs) 0 0;
    color: var(--ds-text-muted);
    font-size: 0.875rem;
}

.page-body {
    padding: var(--ds-space-xl) var(--ds-space-2xl);
}

/* ---------- Dashboard Stats ---------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--ds-space-md);
    margin-bottom: var(--ds-space-xl);
}

.stat-card {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    padding: var(--ds-space-lg);
}

.stat-card .stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ds-text-muted);
    margin-bottom: var(--ds-space-xs);
}

.stat-card .stat-value {
    font-family: var(--ds-font-heading);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--ds-text);
}

.stat-card .stat-change {
    font-size: 0.75rem;
    margin-top: var(--ds-space-xs);
}

.stat-change.positive { color: var(--ds-secondary); }
.stat-change.negative { color: var(--ds-danger); }

/* ---------- Login ---------- */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--ds-bg);
}

.login-card {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    padding: var(--ds-space-2xl);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--ds-shadow-md);
}

.login-card h1 {
    text-align: center;
    color: var(--ds-primary);
    margin-bottom: var(--ds-space-xs);
}

.login-card .login-subtitle {
    text-align: center;
    color: var(--ds-text-muted);
    font-size: 0.875rem;
    margin-bottom: var(--ds-space-xl);
}

.login-card .btn-primary {
    width: 100%;
    justify-content: center;
    padding: 0.625rem 1rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--ds-border);
    }

    .main-content {
        margin-left: 0;
    }

    .page-header,
    .page-body {
        padding-left: var(--ds-space-md);
        padding-right: var(--ds-space-md);
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ---- Playbook editor ---- */
.pb-status { display: flex; justify-content: space-between; align-items: center; gap: var(--ds-space-md); border-left: 3px solid var(--ds-border); }
.pb-status.is-on { border-left-color: var(--ds-success); background: var(--ds-success-light); }
.pb-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: var(--ds-space-lg); align-items: start; }
.pb-detail { display: grid; grid-template-columns: 1fr auto auto; gap: var(--ds-space-sm); align-items: center; padding: var(--ds-space-sm) 0; border-top: 1px solid var(--ds-border); }
.pb-detail:first-of-type { border-top: 0; }
.pb-detail-main { display: grid; gap: var(--ds-space-xs); }
.pb-detail-actions { display: flex; gap: var(--ds-space-xs); }
.pb-required, .pb-check { display: inline-flex; align-items: center; gap: var(--ds-space-xs); font-size: 0.875rem; white-space: nowrap; }
.pb-check { white-space: normal; margin-bottom: var(--ds-space-xs); }
.pb-try { position: sticky; top: var(--ds-space-md); display: flex; flex-direction: column; gap: var(--ds-space-sm); }
.pb-chat { display: flex; flex-direction: column; gap: var(--ds-space-sm); min-height: 320px; max-height: 60vh; overflow-y: auto; padding: var(--ds-space-md); background: var(--ds-bg); border: 1px solid var(--ds-border); border-radius: 0.5rem; }
.pb-msg { max-width: 85%; padding: 0.55rem 0.8rem; border-radius: 0.9rem; line-height: 1.45; font-size: 0.925rem; white-space: pre-wrap; }
.pb-bot { align-self: flex-start; background: var(--ds-surface); border: 1px solid var(--ds-border); border-bottom-left-radius: 0.3rem; }
.pb-visitor { align-self: flex-end; background: var(--ds-primary); color: #fff; border-bottom-right-radius: 0.3rem; }
.pb-event { align-self: stretch; max-width: none; padding: 0.15rem 0.4rem; font-family: var(--ds-font-mono); font-size: 0.75rem; color: var(--ds-text-muted); border-radius: 0; }
.pb-error { color: var(--ds-danger); }
.pb-found { display: flex; flex-wrap: wrap; gap: var(--ds-space-xs); }
.pb-send { display: flex; gap: var(--ds-space-sm); }
.pb-send .form-control { flex: 1; }
@media (max-width: 1100px) {
    .pb-grid { grid-template-columns: 1fr; }
    .pb-try { position: static; }
}
