/* ═══════════════════════════════════════════
   Kiptabs OrgAdmin — Design System v3.2 REFINED
   Layout preserved, visual polish enhanced
   SCROLLING FIXED ✅
   ═══════════════════════════════════════════ */

:root {
    /* Backgrounds */
    --bg: #090d14;
    --bg-elevated: #0d1220;
    --surface: #111827;
    --surface-hover: #182032;
    --card: #172235;
    --card-hover: #1c2840;
    
    /* Borders */
    --border: #1f2d45;
    --border-light: #2a3a55;
    
    /* Text */
    --text: #e9eef5;
    --text-secondary: #9badc0;
    --muted: #586b85;
    
    /* Brand - ORIGINAL GREEN (you were right!) */
    --green: #1dd176;
    --green-bg: rgba(29,209,118,0.1);
    --green-glow: rgba(29,209,118,0.15);
    --green-light: #22e680;
    
    /* Accents */
    --blue: #4da8ff;
    --blue-bg: rgba(77,168,255,0.1);
    --purple: #a78bfa;
    --purple-bg: rgba(167,139,250,0.1);
    --orange: #fb923c;
    --orange-bg: rgba(251,146,60,0.1);
    --red: #f87171;
    --red-bg: rgba(248,113,113,0.1);
    
    /* Radius */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 4px;
    
    /* Shadows - ENHANCED */
    --shadow-card: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.03);
    --shadow-elevated: 0 8px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
    --shadow-modal: 0 20px 60px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.08);
    
    /* Transitions - SMOOTHER */
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Layout - ORIGINAL PRESERVED */
    --sidebar-w: 240px;
}

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

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
    overflow: auto;
}

/* ── Header ── */
.header {
    background: var(--surface);
    padding: 0 28px;
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 8px rgba(0,0,0,0.3);
}

.header-left { display: flex; align-items: center; gap: 14px; }
.header h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.header-right { display: flex; align-items: center; gap: 12px; }

.user-badge {
    background: var(--card);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    font-weight: 500;
    box-shadow: var(--shadow-card);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 4px;
}

.user-badge:hover {
    border-color: var(--border-light);
    transform: translateY(-1px);
}

.hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
}

.hamburger:hover { background: var(--card); color: var(--text); }

/* ── Buttons - ENHANCED ── */
.btn {
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow-card);
}

.btn-primary {
    background: linear-gradient(135deg, var(--green), #17b860);
    color: #000;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--green-light), var(--green));
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--green-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    box-shadow: none;
}

.btn-outline:hover {
    border-color: var(--text-secondary);
    color: var(--text);
    box-shadow: var(--shadow-card);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 6px 12px;
    box-shadow: none;
}

.btn-ghost:hover { background: var(--card); color: var(--text); }

.btn-sm { padding: 5px 12px; font-size: 12px; }

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-xs);
    display: flex;
    box-shadow: none;
    transition: all var(--transition);
}

.btn-icon:hover { background: var(--card); color: var(--text); }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ── Layout - FIXED FOR SCROLLING ── */
.layout { 
    display: flex; 
    height: calc(100vh - 60px); 
    overflow: visible;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 12px;
    flex-shrink: 0;
    transition: transform 0.3s;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    height: calc(100vh - 60px);
    position: sticky;
    top: 60px;
    box-shadow: 1px 0 8px rgba(0,0,0,0.2);
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    position: relative;
}

/* ENHANCED: Green indicator bar for active state */
.sidebar a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: var(--green);
    border-radius: 0 2px 2px 0;
    transition: height var(--transition);
}

.sidebar a:hover { background: var(--card); color: var(--text); }

.sidebar a.active {
    background: var(--card);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--shadow-card);
}

.sidebar a.active::before {
    height: 24px;
}

.sidebar .nav-icon {
    font-size: 16px;
    width: 22px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.main-content {
    flex: 1;
    padding: 28px 32px;
    overflow-y: auto;
    overflow-x: hidden;
    max-width: 1400px;
    height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
    background: radial-gradient(ellipse at 50% 0%, rgba(29,209,118,0.02) 0%, transparent 60%);
}

/* ── Page Hero - ORIGINAL PRESERVED ── */
.page-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
    flex-shrink: 0;
}

.page-hero h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.page-hero p { color: var(--text-secondary); margin-top: 4px; font-size: 14px; }
.page-hero-date { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ── Stat Cards - ORIGINAL PRESERVED ── */
.stat-grid { 
    display: grid; 
    grid-template-columns: repeat(4, 1fr); 
    gap: 16px; 
    margin-bottom: 28px;
    flex-shrink: 0;
}

.stat-card {
    background: var(--card);
    padding: 22px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    gap: 16px;
    align-items: center;
    transition: all var(--transition);
    cursor: default;
    box-shadow: var(--shadow-card);
}

.stat-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-elevated);
}

.stat-icon-wrap {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.accent-green .stat-icon-wrap {
    background: var(--green-bg);
    color: var(--green);
    box-shadow: 0 0 20px var(--green-glow);
}

.accent-blue .stat-icon-wrap { background: var(--blue-bg); color: var(--blue); }
.accent-purple .stat-icon-wrap { background: var(--purple-bg); color: var(--purple); }
.accent-orange .stat-icon-wrap { background: var(--orange-bg); color: var(--orange); }

.stat-value {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -1px;
    line-height: 1;
}

.accent-green .stat-value { color: var(--green); }
.accent-blue .stat-value { color: var(--blue); }
.accent-purple .stat-value { color: var(--purple); }
.accent-orange .stat-value { color: var(--orange); }

.stat-label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.stat-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Card Layout - ORIGINAL PRESERVED ── */
.card-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 16px;
    margin-bottom: 20px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    transition: all var(--transition);
    overflow: hidden;
}

.card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-elevated);
}

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

.card-header h3 { font-size: 15px; font-weight: 700; }
.card-body { padding: 20px 22px; }

/* ── Forms - ENHANCED POLISH ── */
.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    color: var(--text-secondary);
    margin-bottom: 7px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.form-group label .required { color: var(--red); margin-left: 2px; }

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
    font-family: inherit;
    transition: all var(--transition);
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
    border-color: var(--border-light);
}

/* ENHANCED: Green glow on focus */
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px var(--green-glow);
}

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

.form-group .hint {
    font-size: 11px;
    color: var(--muted);
    margin-top: 5px;
}

/* ── Tables - ORIGINAL LAYOUT ── */
.content-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
    min-height: 0;
}

.content-scroll::-webkit-scrollbar { width: 6px; }
.content-scroll::-webkit-scrollbar-track { background: transparent; }
.content-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.content-scroll::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

.table-wrapper {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-card);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-elevated);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

thead th {
    padding: 14px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: all var(--transition);
}

tbody tr:hover { background: var(--card-hover); }
tbody tr.clickable-row { cursor: pointer; }
tbody tr.clickable-row:hover { background: var(--surface-hover); }
tbody td { padding: 14px 16px; font-size: 13px; }

/* ── Modals - ENHANCED + BACKDROP CLICK ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

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

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-modal);
    animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

.modal-header h3 { font-size: 17px; font-weight: 700; }

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-xs);
    font-size: 20px;
    line-height: 1;
    transition: all var(--transition);
}

.modal-close:hover { background: var(--card); color: var(--text); }

.modal-body { 
    padding: 24px; 
    overflow-y: auto; 
    flex: 1;
    min-height: 0;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ── Search Bar - ORIGINAL ── */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-bar input {
    flex: 1;
    min-width: 250px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: all var(--transition);
}

.search-bar input:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px var(--green-glow);
}

.search-bar select {
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

/* ── Badges - ENHANCED ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.badge.online { background: var(--green-bg); color: var(--green); }
.badge.offline { background: var(--red-bg); color: var(--red); }

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Toast - ENHANCED ── */
.toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    box-shadow: var(--shadow-elevated);
    min-width: 300px;
    animation: toastSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ── Utilities ── */
.text-muted { color: var(--muted); }
.text-secondary { color: var(--text-secondary); }
.text-primary { color: var(--green); }
.text-error { color: var(--red); }

.clickable-row { cursor: pointer; transition: all var(--transition); }
.clickable-row:hover { background: var(--card-hover) !important; }

/* ── Responsive - ORIGINAL ── */
@media (max-width: 768px) {
    :root { --sidebar-w: 0; }
    
    .header { padding: 0 20px; }
    .hamburger { display: flex; }
    
    .sidebar {
        position: fixed;
        left: 0;
        top: 60px;
        height: calc(100vh - 60px);
        transform: translateX(-100%);
        z-index: 999;
        box-shadow: var(--shadow-elevated);
    }
    
    .sidebar.open { transform: translateX(0); }
    
    .main-content { padding: 20px; }
    .stat-grid { grid-template-columns: 1fr; }
    .card-grid { grid-template-columns: 1fr; }
    .search-bar { flex-direction: column; }
    .search-bar input { min-width: 100%; }
}

/* ═══════════════════════════════════════════
   Organization Switcher - Complete Styling
   ═══════════════════════════════════════════ */

.org-switcher {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 16px;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
}

.org-switcher:hover {
    border-color: var(--border-light);
    background: var(--card-hover);
}

.org-switcher-current {
    display: flex;
    align-items: center;
    gap: 10px;
}

.org-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--green), #17b860);
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
    flex-shrink: 0;
}

.org-name {
    flex: 1;
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.org-chevron {
    color: var(--muted);
    font-size: 14px;
    transition: transform var(--transition);
    display: flex;
    align-items: center;
}

.org-switcher:hover .org-chevron {
    color: var(--text-secondary);
}

.org-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-elevated);
    z-index: 1000;
    max-height: 400px;
    overflow-y: auto;
    animation: dropdownSlide 0.2s ease;
}

@keyframes dropdownSlide {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.org-dropdown-header {
    padding: 12px 14px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
}

.org-dropdown-item {
    padding: 12px 14px;
    cursor: pointer;
    transition: all var(--transition);
    border-bottom: 1px solid var(--border);
}

.org-dropdown-item:last-child {
    border-bottom: none;
}

.org-dropdown-item:hover {
    background: var(--card);
}

.org-dropdown-item.active {
    background: var(--green-bg);
    border-left: 3px solid var(--green);
}

.org-item-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 3px;
}

.org-item-account {
    font-size: 11px;
    color: var(--muted);
    font-family: 'Monaco', 'Courier New', monospace;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

.org-dropdown::-webkit-scrollbar {
    width: 6px;
}

.org-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.org-dropdown::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.org-dropdown::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ═══════════════════════════════════════════
   Profile Page - Beautiful Grid Layout
   ═══════════════════════════════════════════ */

.profile-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.profile-item {
    padding: 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.profile-item:hover {
    border-color: var(--border-light);
    background: var(--bg-elevated);
}

.profile-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.profile-value {
    font-size: 15px;
    color: var(--text);
    line-height: 1.6;
    word-break: break-word;
}

.profile-value a {
    text-decoration: none;
    transition: color var(--transition);
}

.profile-value a:hover {
    text-decoration: underline;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-state p {
    margin: 0;
    font-size: 14px;
}

@media (max-width: 768px) {
    .profile-grid {
        gap: 12px;
    }
    
    .profile-item {
        padding: 12px;
    }
}

/* ═══════════════════════════════════════════
   Dynamic Content App Scrolling
   ═══════════════════════════════════════════ */

#profileApp,
#dashboardApp {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}