/* ══════════════════════════════════════════
   SKALA CODE — Design System & Shared Layout
   ══════════════════════════════════════════ */

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --font-mono: 'SF Mono', ui-monospace, 'Cascadia Code', 'Fira Code', monospace;

    /* Neutral scale */
    --n-0: #ffffff; --n-25: #fafafa; --n-50: #f5f5f7;
    --n-100: #ebebef; --n-150: #e0e0e6; --n-200: #d1d1d9;
    --n-300: #b4b4bf; --n-400: #8e8e9d; --n-500: #6b6b7b;
    --n-600: #4b4b58; --n-700: #353541; --n-800: #23232d;
    --n-900: #16161d; --n-950: #0e0e13;

    /* Accent — blue */
    --a-700: #1d4ed8; --a-600: #2563eb; --a-500: #3b82f6;
    --a-400: #60a5fa; --a-300: #93bbfd; --a-200: #bfdbfe;
    --a-100: #dbeafe; --a-50: #eff6ff;
    --a-glow: rgba(37,99,235,0.12);
    --a-surface: rgba(37,99,235,0.06);

    /* Status */
    --green: #16a34a; --green-bg: #f0fdf4;
    --amber: #d97706; --amber-bg: #fffbeb;
    --red: #dc2626; --red-bg: #fef2f2;
    --cyan: #0891b2;

    /* Alpha */
    --b03: rgba(0,0,0,0.03); --b05: rgba(0,0,0,0.05);
    --b07: rgba(0,0,0,0.07); --b10: rgba(0,0,0,0.10);
    --b14: rgba(0,0,0,0.14); --b20: rgba(0,0,0,0.20);
    --b40: rgba(0,0,0,0.40); --b60: rgba(0,0,0,0.55);

    /* Layout */
    --sidebar-w: 272px;
    --topbar-h: 53px;
    --chat-max: 740px;

    /* Motion */
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --fast: 100ms; --norm: 180ms; --slow: 320ms;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: var(--font-sans);
    background: var(--n-0);
    color: var(--n-800);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

::selection { background: rgba(37,99,235,0.2); color: var(--n-900); }

/* ════════ LAYOUT ════════ */
#app { height: 100%; display: flex; }

/* ════════ SIDEBAR ════════ */
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: var(--n-25);
    border-right: 1px solid var(--n-150);
    display: flex; flex-direction: column;
    z-index: 20; position: relative;
    transition: transform var(--slow) var(--ease);
}

.sb-head {
    padding: 20px 20px 16px;
    display: flex; align-items: center; gap: 12px;
}

.sb-logo {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--a-600);
    display: grid; place-items: center; flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(37,99,235,0.3);
}
.sb-logo svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.sb-brand-name { font-size: 15px; font-weight: 700; letter-spacing: -0.4px; color: var(--n-900); }
.sb-brand-tag { font-size: 11px; color: var(--n-400); margin-top: 1px; }

/* Section */
.sb-section {
    padding: 14px 16px 6px;
    font-size: 10px; font-weight: 700;
    color: var(--n-400); text-transform: uppercase;
    letter-spacing: 1px;
}

/* Nav */
.sb-nav { flex: 1; overflow-y: auto; padding: 2px 8px; }
.sb-nav::-webkit-scrollbar { width: 0; }

.sb-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px;
    font-size: 13px; color: var(--n-500); cursor: pointer;
    transition: all var(--fast) ease; position: relative;
    user-select: none; margin-bottom: 1px;
    text-decoration: none;
}

.sb-item:hover { background: var(--b05); color: var(--n-700); }
.sb-item.active { background: var(--a-50); color: var(--a-700); }

.sb-item.active::before {
    content: ''; position: absolute; left: 0; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 18px;
    background: var(--a-500); border-radius: 0 4px 4px 0;
}

.sb-icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; opacity: 0.6; }
.sb-item:hover .sb-icon, .sb-item.active .sb-icon { opacity: 1; }

.sb-badge {
    margin-left: auto; padding: 2px 8px;
    background: var(--a-surface); color: var(--a-600);
    font-size: 10px; font-weight: 600; border-radius: 99px;
}

/* Footer */
.sb-footer {
    padding: 14px 16px; border-top: 1px solid var(--n-150);
    display: flex; align-items: center; gap: 10px;
}

.sb-avatar {
    width: 32px; height: 32px; border-radius: 99px;
    background: var(--a-100);
    display: grid; place-items: center;
    font-size: 12px; font-weight: 700; color: var(--a-600);
    position: relative;
}

.sb-avatar::after {
    content: ''; position: absolute; bottom: -1px; right: -1px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--green); border: 2px solid var(--n-25);
}

.sb-user-name { font-size: 13px; font-weight: 500; color: var(--n-800); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sb-user-role { font-size: 11px; color: var(--n-400); }

.sb-settings {
    width: 30px; height: 30px; border-radius: 8px;
    border: none; background: transparent; color: var(--n-400);
    cursor: pointer; display: grid; place-items: center;
    transition: all var(--fast) ease;
}
.sb-settings:hover { background: var(--b07); color: var(--n-600); }
.sb-settings svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.7; }

/* ════════ MAIN ════════ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--n-0); }

/* Topbar */
.topbar {
    flex-shrink: 0; height: var(--topbar-h);
    padding: 0 24px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--n-150);
    background: rgba(255,255,255,0.85);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
}

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

.tb-toggle {
    display: none; width: 34px; height: 34px; border-radius: 8px;
    border: none; background: transparent; color: var(--n-500);
    cursor: pointer; place-items: center;
    transition: all var(--fast) ease;
}
.tb-toggle:hover { background: var(--b07); color: var(--n-700); }
.tb-toggle svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }

.tb-title { font-size: 14px; font-weight: 600; letter-spacing: -0.2px; color: var(--n-700); }

.tb-pill {
    padding: 3px 10px; border-radius: 99px;
    background: var(--a-50); color: var(--a-600);
    font-size: 10px; font-weight: 700; letter-spacing: 0.4px;
    text-transform: uppercase;
    border: 1px solid var(--a-200);
}

.tb-right { display: flex; align-items: center; gap: 4px; }

.tb-btn {
    width: 34px; height: 34px; border-radius: 8px;
    border: none; background: transparent; color: var(--n-400);
    cursor: pointer; display: grid; place-items: center;
    transition: all var(--fast) ease;
}
.tb-btn:hover { background: var(--b07); color: var(--n-700); }
.tb-btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ════════ TOAST ════════ */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
    padding: 12px 24px; border-radius: 10px;
    background: var(--n-800); color: #fff;
    font: 500 13px var(--font-sans);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    transition: transform var(--slow) var(--ease);
    z-index: 300;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ════════ MOBILE OVERLAY ════════ */
.sb-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.3); backdrop-filter: blur(4px);
    z-index: 15;
}

/* ════════ SHARED FORM STYLES ════════ */
.field { margin-bottom: 16px; }
.field label {
    display: block; font-size: 12px; font-weight: 600;
    color: var(--n-500); margin-bottom: 6px;
}
.field-hint { font-size: 11px; color: var(--n-400); margin-top: 4px; }
.field input, .field select, .field textarea {
    width: 100%; padding: 10px 14px;
    border: 1px solid var(--n-200); border-radius: 10px;
    font: 400 14px var(--font-sans); color: var(--n-800);
    background: var(--n-0); outline: none;
    transition: border-color var(--fast) ease, box-shadow var(--fast) ease;
}
.field textarea { resize: vertical; min-height: 72px; font-family: var(--font-sans); line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--a-400);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.field input::placeholder, .field textarea::placeholder { color: var(--n-300); }

/* ════════ RESPONSIVE ════════ */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); z-index: 30; }
    .sidebar.open { transform: translateX(0); }
    .sb-overlay.open { display: block; }
    .tb-toggle { display: grid; }
}

/* ════════ WHATSAPP CONFIG VIEW ════════ */
.whatsapp-config-view {
    display: none;
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
    overflow-y: auto;
    height: calc(100vh - var(--topbar-h));
}

.whatsapp-config-view.active {
    display: block;
}

.config-header {
    margin-bottom: 24px;
}

.config-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--n-900);
    margin-bottom: 8px;
}

.config-header p {
    font-size: 14px;
    color: var(--n-500);
}

.config-status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.config-card {
    background: var(--n-0);
    border: 1px solid var(--n-200);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px var(--b05);
}

.config-card-header {
    padding: 16px 20px;
    background: var(--n-50);
    border-bottom: 1px solid var(--n-200);
    display: flex;
    align-items: center;
    gap: 12px;
}

.config-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.config-card-icon svg {
    width: 20px;
    height: 20px;
    stroke: white;
    fill: none;
    stroke-width: 2;
}

.waha-icon { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.evolution-icon { background: linear-gradient(135deg, #10b981 0%, #059669 100%); }

.config-card-title h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--n-900);
    margin-bottom: 4px;
}

.config-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.config-badge.success { background: var(--green-bg); color: var(--green); }
.config-badge.warning { background: var(--amber-bg); color: var(--amber); }
.config-badge.error { background: var(--red-bg); color: var(--red); }
.config-badge.neutral { background: var(--n-100); color: var(--n-500); }

.config-card-body {
    padding: 20px;
}

.config-info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--n-100);
}

.config-info-item:last-child {
    border-bottom: none;
}

.config-info-item label {
    font-size: 13px;
    font-weight: 500;
    color: var(--n-500);
}

.config-info-item span {
    font-size: 13px;
    color: var(--n-700);
    font-weight: 400;
}

.config-qr-section {
    margin-top: 20px;
}

.config-qr-section label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--n-700);
    margin-bottom: 12px;
}

.config-qr-placeholder {
    background: var(--n-50);
    border: 2px dashed var(--n-200);
    border-radius: 10px;
    padding: 24px;
    text-align: center;
    min-height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.config-qr-placeholder img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.config-loading {
    font-size: 14px;
    color: var(--n-400);
}

.config-loading i {
    font-size: 24px;
    margin-bottom: 8px;
}

.config-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.config-btn {
    flex: 1;
    min-width: 140px;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--norm) var(--ease);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.config-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--b07);
}

.config-btn.btn-primary {
    background: var(--a-600);
    color: white;
}

.config-btn.btn-primary:hover {
    background: var(--a-700);
}

.config-btn.btn-secondary {
    background: var(--n-100);
    color: var(--n-700);
}

.config-btn.btn-secondary:hover {
    background: var(--n-200);
}

.config-info-section {
    background: var(--n-0);
    border: 1px solid var(--n-200);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px var(--b05);
}

.config-info-section h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--n-900);
    margin-bottom: 16px;
}

.config-info-content {
    font-size: 14px;
    color: var(--n-600);
    line-height: 1.6;
}

.config-info-content p {
    margin-bottom: 12px;
}

.config-info-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.config-info-content li {
    margin-bottom: 6px;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .whatsapp-config-view {
        padding: 16px;
    }

    .config-status-grid {
        grid-template-columns: 1fr;
    }

    .config-actions {
        flex-direction: column;
    }

    .config-btn {
        width: 100%;
    }
}
