/* ═══════════════════════════════════════════
   KKHS SEO Agency — 3D Style Theme
   Colors: Deep Blue + Red + White
   ═══════════════════════════════════════════ */

:root {
    --blue-deep: #0a1628;
    --blue-dark: #0d2137;
    --blue-mid: #1a3a5c;
    --blue-primary: #1565c0;
    --blue-light: #42a5f5;
    --blue-glow: #64b5f6;
    --red-primary: #d32f2f;
    --red-light: #ef5350;
    --red-dark: #b71c1c;
    --white: #ffffff;
    --gray-100: #f5f7fa;
    --gray-200: #e8ecf1;
    --gray-300: #c5cdd8;
    --gray-500: #7b8a9e;
    --gray-700: #3d4f65;
    --text: #e1e8f0;
    --text-dim: #8899aa;
    --card-bg: rgba(13, 33, 55, 0.85);
    --card-border: rgba(30, 80, 140, 0.3);
    --sidebar-w: 260px;
    --header-h: 64px;
    --radius: 14px;
    --shadow-3d: 0 4px 6px rgba(0,0,0,0.3), 0 10px 30px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.06);
    --shadow-card: 0 8px 32px rgba(0,0,0,0.35), 0 2px 8px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.05);
    --shadow-btn: 0 4px 15px rgba(21,101,192,0.4), 0 2px 6px rgba(0,0,0,0.3);
    --shadow-red: 0 4px 15px rgba(211,47,47,0.4), 0 2px 6px rgba(0,0,0,0.3);
    --green: #4caf50;
    --yellow: #ff9800;
    --gradient-blue: linear-gradient(135deg, #1565c0, #0d47a1);
    --gradient-red: linear-gradient(135deg, #e53935, #b71c1c);
    --gradient-surface: linear-gradient(180deg, #0d2137 0%, #0a1628 100%);
}

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

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gradient-surface);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--blue-deep); }
::-webkit-scrollbar-thumb { background: var(--blue-mid); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--blue-primary); }

/* ─── LOGIN PAGE ─── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 30% 20%, rgba(21,101,192,0.15) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 80%, rgba(211,47,47,0.1) 0%, transparent 50%),
                var(--gradient-surface);
}

.login-box {
    width: 420px;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 48px 40px;
    box-shadow: var(--shadow-card), 0 0 60px rgba(21,101,192,0.1);
    transform: perspective(800px) rotateX(2deg);
    transition: transform 0.3s ease;
}
.login-box:hover { transform: perspective(800px) rotateX(0deg); }

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}
.login-logo h1 {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--blue-light), var(--white));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1px;
}
.login-logo h1 span {
    background: linear-gradient(135deg, var(--red-primary), var(--red-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.login-logo p { color: var(--text-dim); font-size: 14px; margin-top: 4px; }

/* ─── FORM ELEMENTS ─── */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-300);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(10, 22, 40, 0.8);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}
.form-input:focus {
    border-color: var(--blue-primary);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 0 0 3px rgba(21,101,192,0.2);
}
.form-input::placeholder { color: var(--gray-500); }

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237b8a9e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-input { resize: vertical; min-height: 80px; }

/* ─── BUTTONS ─── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 24px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    text-decoration: none;
    letter-spacing: 0.3px;
}
.btn-primary {
    background: var(--gradient-blue);
    color: var(--white);
    box-shadow: var(--shadow-btn);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(21,101,192,0.5), 0 3px 8px rgba(0,0,0,0.3);
}
.btn-red {
    background: var(--gradient-red);
    color: var(--white);
    box-shadow: var(--shadow-red);
}
.btn-red:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(211,47,47,0.5);
}
.btn-outline {
    background: transparent;
    color: var(--blue-light);
    border: 1px solid var(--blue-mid);
}
.btn-outline:hover { background: rgba(21,101,192,0.1); }
.btn-sm { padding: 7px 14px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn i { font-size: 14px; }

/* ─── APP LAYOUT ─── */
.app-layout { display: flex; min-height: 100vh; }

/* ─── SIDEBAR ─── */
.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #091520 0%, #060e18 100%);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: 4px 0 30px rgba(0,0,0,0.3);
}

.sidebar-brand {
    padding: 20px 24px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-brand .brand-icon {
    width: 42px;
    height: 42px;
    background: var(--gradient-blue);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 12px rgba(21,101,192,0.4);
}
.sidebar-brand h2 {
    font-size: 18px;
    font-weight: 800;
    color: var(--white);
    line-height: 1.2;
}
.sidebar-brand h2 span {
    color: var(--red-primary);
    font-size: 11px;
    font-weight: 600;
    display: block;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}
.nav-section {
    padding: 8px 20px 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gray-500);
    font-weight: 700;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 24px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    margin: 1px 0;
}
.nav-item:hover {
    color: var(--text);
    background: rgba(21,101,192,0.08);
}
.nav-item.active {
    color: var(--blue-light);
    background: rgba(21,101,192,0.12);
    border-left-color: var(--blue-primary);
}
.nav-item i { width: 20px; text-align: center; font-size: 16px; }
.nav-item .badge {
    margin-left: auto;
    background: var(--red-primary);
    color: white;
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 700;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-footer .avatar {
    width: 34px; height: 34px;
    background: var(--gradient-red);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: white;
}
.sidebar-footer .user-info { flex: 1; }
.sidebar-footer .user-info .name { font-size: 13px; font-weight: 600; }
.sidebar-footer .user-info .role { font-size: 11px; color: var(--text-dim); }
.sidebar-footer .logout-btn {
    color: var(--text-dim);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    transition: color 0.2s;
}
.sidebar-footer .logout-btn:hover { color: var(--red-primary); }

/* ─── MAIN CONTENT ─── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 24px 32px;
    min-height: 100vh;
}

/* ─── PAGE HEADER ─── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}
.page-header h1 {
    font-size: 26px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--white), var(--gray-300));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.page-header .subtitle {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* ─── STAT CARDS ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow-card);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-blue);
}
.stat-card.red::before { background: var(--gradient-red); }
.stat-card:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: var(--shadow-card), 0 12px 40px rgba(21,101,192,0.15);
}
.stat-card .stat-icon {
    width: 44px; height: 44px;
    background: rgba(21,101,192,0.12);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--blue-light);
    margin-bottom: 14px;
}
.stat-card.red .stat-icon {
    background: rgba(211,47,47,0.12);
    color: var(--red-light);
}
.stat-card .stat-value {
    font-size: 30px;
    font-weight: 800;
    color: var(--white);
    line-height: 1;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* ─── CARDS / PANELS ─── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    margin-bottom: 24px;
    overflow: hidden;
}
.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(10,22,40,0.5);
}
.card-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--white);
}
.card-body { padding: 24px; }

/* ─── TABLES ─── */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
}
th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--gray-500);
    font-weight: 700;
    border-bottom: 1px solid var(--card-border);
    background: rgba(10,22,40,0.4);
}
td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid rgba(30,80,140,0.1);
    color: var(--text);
}
tr:hover td { background: rgba(21,101,192,0.04); }

/* ─── BADGES ─── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-green { background: rgba(76,175,80,0.15); color: #66bb6a; }
.badge-red { background: rgba(211,47,47,0.15); color: #ef5350; }
.badge-blue { background: rgba(21,101,192,0.15); color: #42a5f5; }
.badge-yellow { background: rgba(255,193,7,0.15); color: #ffca28; }
.badge-gray { background: rgba(120,144,166,0.15); color: #90a4ae; }

/* ─── MODAL ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal {
    background: linear-gradient(180deg, #0d2137, #0a1628);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    width: 560px;
    max-width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    transform: scale(0.9);
    transition: transform 0.3s;
}
.modal-overlay.active .modal { transform: scale(1); }
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
    width: 32px; height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-dim);
    font-size: 18px;
    transition: all 0.2s;
}
.modal-close:hover { background: rgba(211,47,47,0.15); color: var(--red-light); }
.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--card-border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ─── EMPTY STATE ─── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-dim);
}
.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.empty-state h3 { font-size: 18px; color: var(--gray-300); margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

/* ─── LOADING ─── */
.spinner {
    display: inline-block;
    width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,0.2);
    border-top-color: var(--blue-light);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10,22,40,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.loading-overlay .spinner { width: 40px; height: 40px; border-width: 3px; }

/* ─── GRID HELPERS ─── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-10 { gap: 10px; }
.gap-20 { gap: 20px; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.text-center { text-align: center; }
.text-red { color: var(--red-primary) !important; }
.text-green { color: #66bb6a !important; }
.text-blue { color: var(--blue-light) !important; }

/* ─── TOAST ─── */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 3000; }
.toast {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 14px 20px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-card);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
    min-width: 280px;
}
.toast.success { border-left: 3px solid #66bb6a; }
.toast.error { border-left: 3px solid var(--red-primary); }
.toast.info { border-left: 3px solid var(--blue-primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── SETTINGS SECTIONS ─── */
.settings-section {
    margin-bottom: 32px;
}
.settings-section h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--white);
}
.settings-section h3 i { color: var(--blue-light); }
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.api-key-card {
    background: rgba(10,22,40,0.6);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 18px;
    transition: all 0.2s;
}
.api-key-card:hover { border-color: var(--blue-mid); }
.api-key-card .provider-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.api-key-card .status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.api-key-card .status-dot.active { background: #66bb6a; box-shadow: 0 0 6px rgba(102,187,106,0.5); }
.api-key-card .status-dot.inactive { background: var(--gray-500); }

/* ─── QUICK ACTION CARDS ─── */
.quick-action-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 12px 40px rgba(30,136,229,0.25), 0 4px 12px rgba(0,0,0,0.3);
    border-color: var(--blue-light);
}
.quick-action-card:active {
    transform: translateY(-1px) scale(0.98);
}

/* ─── COMMAND CENTER PROMPT ─── */
#cmdPrompt:focus {
    border-color: var(--blue-light);
    box-shadow: 0 0 20px rgba(30,136,229,0.2);
    outline: none;
}

/* ─── ORG CHART / HIERARCHY ─── */
.org-tree {
    display: flex;
    justify-content: center;
    padding: 20px 0;
    min-width: 800px;
}

.org-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.org-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 16px 14px 12px;
    min-width: 160px;
    max-width: 190px;
    text-align: center;
    position: relative;
    box-shadow: var(--shadow-card);
    transition: all 0.3s ease;
    margin: 0 6px;
}
.org-card:hover {
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 12px 40px rgba(30,136,229,0.25);
    border-color: var(--blue-light);
    z-index: 10;
}
.org-card-active {
    border-color: var(--green) !important;
    box-shadow: 0 0 20px rgba(76,175,80,0.3), var(--shadow-card);
    animation: pulseGreen 2s infinite;
}
@keyframes pulseGreen {
    0%, 100% { box-shadow: 0 0 20px rgba(76,175,80,0.2), var(--shadow-card); }
    50% { box-shadow: 0 0 30px rgba(76,175,80,0.4), var(--shadow-card); }
}

.org-card-level {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 9px;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

.org-card-icon {
    font-size: 28px;
    margin: 8px 0 6px;
}
.org-card-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 2px;
}
.org-card-name {
    font-size: 10px;
    color: var(--text-dim);
    margin-bottom: 6px;
}
.org-card-status {
    margin: 4px 0;
}
.org-card-tasks {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 4px;
}
.org-card-last {
    font-size: 9px;
    color: var(--gray-500);
    margin-top: 2px;
}

.org-children {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-top: 20px;
    padding-top: 20px;
    position: relative;
}

/* Vertical line from parent to children bar */
.org-children::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 20px;
    background: linear-gradient(180deg, var(--blue-light), var(--card-border));
    transform: translateX(-50%);
}

/* Horizontal connecting bar across children */
.org-children::after {
    content: '';
    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--card-border);
}

/* Vertical line from bar down to each child */
.org-children > .org-node::before {
    content: '';
    position: absolute;
    top: -20px;
    left: 50%;
    width: 2px;
    height: 20px;
    background: var(--card-border);
    transform: translateX(-50%);
}

/* Single child = no horizontal bar needed, just a straight line */
.org-children:has(> .org-node:only-child)::after {
    display: none;
}

/* First child - clip left half of horizontal bar */
.org-children > .org-node:first-child:not(:only-child) ~ .org-node {} /* just for specificity */

/* ─── RESPONSIVE ─── */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 16px; }
    .stats-grid { grid-template-columns: 1fr; }
    .login-box { width: 95%; padding: 32px 24px; }
}
