/* ── Reset & Variables ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #050810;
    --bg-secondary: rgba(15, 21, 37, 0.4);
    --bg-card: rgba(21, 29, 48, 0.5);
    --bg-card-hover: rgba(31, 44, 71, 0.6);
    --bg-sidebar: rgba(10, 16, 32, 0.6);
    --bg-input: rgba(17, 27, 46, 0.6);
    --text-primary: #e4e8f2;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.15);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.15);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.15);
    --border: rgba(255, 255, 255, 0.08);
    --border-active: rgba(99, 102, 241, 0.4);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

body {
    background: radial-gradient(circle at top left, #1a1a2e, #0f1525, #080c16);
    background-attachment: fixed;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
    width: 250px;
    min-width: 250px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header { padding: 20px 18px; border-bottom: 1px solid var(--border); }

.logo { display: flex; align-items: center; gap: 12px; }
.logo-img {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    object-fit: cover;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.15);
}
.logo-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
.logo-title { display: block; font-weight: 700; font-size: 15px; }
.logo-subtitle { display: block; font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1.5px; }

.sidebar-nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px; font-weight: 500;
    transition: var(--transition); cursor: pointer;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text-primary); }
.nav-item.active { background: var(--accent-glow); color: var(--accent-light); font-weight: 600; }
.nav-icon { font-size: 16px; width: 22px; text-align: center; }

.sidebar-footer { padding: 14px 18px; border-top: 1px solid var(--border); }
.bot-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; animation: pulse 2s infinite; }
.status-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ── Main ── */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.top-bar {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 28px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    min-height: 56px;
}
.menu-toggle { display: none; background: none; border: none; color: var(--text-primary); font-size: 22px; cursor: pointer; }
.page-title { font-size: 17px; font-weight: 700; flex: 1; }
.clock { font-size: 12px; color: var(--text-muted); font-weight: 500; letter-spacing: 0.5px; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.content-area { flex: 1; overflow-y: auto; padding: 24px 28px; scroll-behavior: smooth; }

/* ── Cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }

.stat-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px;
    transition: var(--transition); position: relative; overflow: hidden;
}
.stat-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    opacity: 0; transition: var(--transition);
}
.stat-card:hover { border-color: var(--border-active); transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card:hover::before { opacity: 1; }
.stat-card.accent::before { background: linear-gradient(90deg, var(--accent), #8b5cf6); }
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.info::before { background: var(--info); }

.stat-icon { font-size: 24px; margin-bottom: 10px; }
.stat-value {
    font-size: 28px; font-weight: 800; line-height: 1.1;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; font-weight: 500; }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: var(--transition); border: none; font-family: inherit;
}
.btn-primary { background: linear-gradient(135deg, var(--accent), #7c3aed); color: white; box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4); }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: #1a1a1a; }
.btn-ghost { background: rgba(255, 255, 255, 0.04); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); color: var(--text-primary); }

/* ── Inputs ── */
.search-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.search-input {
    flex: 1; min-width: 200px; padding: 10px 16px;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary);
    font-size: 13px; font-family: inherit; outline: none;
    transition: var(--transition);
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

select {
    padding: 10px 12px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary);
    font-size: 13px; font-family: inherit; outline: none; cursor: pointer;
}

/* ── Table ── */
.data-table {
    width: 100%; border-collapse: separate; border-spacing: 0;
    background: var(--bg-card); border-radius: var(--radius);
    border: 1px solid var(--border); overflow: hidden;
}
.data-table thead th {
    padding: 12px 16px; text-align: left; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted);
    background: rgba(0, 0, 0, 0.2); border-bottom: 1px solid var(--border);
}
.data-table tbody td {
    padding: 12px 16px; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.data-table tbody tr:hover { background: rgba(99, 102, 241, 0.04); }

/* ── Tags & Chips ── */
.tag {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 20px;
    font-size: 10px; font-weight: 600; letter-spacing: 0.3px;
}
.tag-team { background: var(--accent-glow); color: var(--accent-light); }

.member-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.member-chip {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 7px; background: rgba(255,255,255,0.05);
    border-radius: 10px; font-size: 10px; color: var(--text-secondary);
}

/* ── Logs ── */
.log-container {
    background: #0a0f18; border-radius: var(--radius);
    border: 1px solid var(--border); padding: 16px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 11px; line-height: 1.7;
    max-height: 60vh; overflow-y: auto; color: #a8b5c8;
}
.log-line { padding: 1px 0; white-space: pre-wrap; word-break: break-all; }

/* ── Modals ── */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px); animation: fadeIn 0.2s ease;
}
.modal {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius); width: 90%; max-width: 800px;
    max-height: 85vh; overflow-y: auto;
    box-shadow: var(--shadow-lg); animation: slideUp 0.3s ease;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-close {
    background: none; border: none; color: var(--text-muted);
    font-size: 18px; cursor: pointer; padding: 4px;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 24px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Glassmorphism ── */
.sidebar, .top-bar, .stat-card, .data-table, .modal, .search-input, select, .log-container {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.15); }

/* ── Google Sheets Container & Grid ── */
.sheets-wrapper {
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100%;
}

.sheets-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.sheets-actions-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.sheets-actions-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sheets-pill-filter {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.sheets-pill-btn {
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.sheets-pill-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.sheets-grid-container {
    flex: 1;
    overflow: auto;
    background: rgba(10, 16, 30, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    position: relative;
    max-height: calc(100vh - 280px);
}

.sheets-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
}

.sheets-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #1e293b;
    color: #94a3b8;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 10.5px;
    padding: 10px 12px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 2px solid rgba(255, 255, 255, 0.15);
    user-select: none;
    text-align: left;
}

.sheets-table th.col-hdr-num {
    width: 45px;
    text-align: center;
    background: #0f172a;
    color: #64748b;
    border-right: 2px solid rgba(255, 255, 255, 0.15);
}

.sheets-table td {
    padding: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.07);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(15, 23, 42, 0.4);
    transition: background 0.15s;
    height: 38px;
    vertical-align: middle;
}

.sheets-table tr:hover td {
    background: rgba(99, 102, 241, 0.08);
}

.sheets-table tr td.row-num {
    text-align: center;
    font-weight: 600;
    color: #64748b;
    font-size: 11px;
    background: #0f172a !important;
    border-right: 2px solid rgba(255, 255, 255, 0.15);
    user-select: none;
}

.sheets-input {
    width: 100%;
    height: 100%;
    min-height: 36px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    padding: 6px 10px;
    font-size: 12px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}

.sheets-input:focus {
    background: rgba(99, 102, 241, 0.15);
    border-color: #6366f1 !important;
    box-shadow: inset 0 0 0 1px #6366f1;
}

.sheets-select {
    width: 100%;
    height: 100%;
    min-height: 36px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    padding: 4px 8px;
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

.sheets-select:focus {
    background: rgba(99, 102, 241, 0.15);
    border-color: #6366f1;
}

.status-badge-active { background: rgba(16, 185, 129, 0.2); color: #34d399; padding: 3px 8px; border-radius: 4px; font-weight: 600; font-size: 11px; }
.status-badge-expiring { background: rgba(245, 158, 11, 0.2); color: #fbbf24; padding: 3px 8px; border-radius: 4px; font-weight: 600; font-size: 11px; }
.status-badge-expired { background: rgba(239, 68, 68, 0.2); color: #f87171; padding: 3px 8px; border-radius: 4px; font-weight: 600; font-size: 11px; }
.status-badge-pending { background: rgba(59, 130, 246, 0.2); color: #60a5fa; padding: 3px 8px; border-radius: 4px; font-weight: 600; font-size: 11px; }

.save-status-indicator {
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
}
.save-status-indicator.saved { color: #10b981; }
.save-status-indicator.unsaved { color: #f59e0b; }

/* ── Sidebar Overlay Backdrop ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.open {
    display: block;
    opacity: 1;
}

/* ── Responsive & Mobile Adaptations ── */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    #app {
        position: relative;
        flex-direction: column;
    }

    /* Off-canvas Mobile Sidebar */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 270px;
        min-width: 270px;
        z-index: 1000;
        background: #090e1a;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 0 35px rgba(0, 0, 0, 0.7);
        border-right: 1px solid rgba(255, 255, 255, 0.12);
    }
    .sidebar.open {
        transform: translateX(0);
    }

    /* Mobile Hamburger Menu Toggle Button */
    .menu-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: var(--radius-sm);
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid var(--border);
        color: var(--text-primary);
        font-size: 20px;
        cursor: pointer;
        transition: var(--transition);
    }
    .menu-toggle:active {
        background: rgba(255, 255, 255, 0.15);
    }

    .top-bar {
        padding: 10px 14px;
        gap: 10px;
        min-height: 52px;
    }

    .page-title {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .clock {
        display: none; /* Hide date/clock on mobile for header space */
    }

    .top-actions {
        gap: 6px;
    }

    .content-area {
        padding: 14px 10px;
        overflow-x: hidden;
    }

    /* Grid layout overrides for mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 16px;
    }

    .stat-card {
        padding: 14px 12px;
    }

    .stat-value {
        font-size: 22px;
    }

    .stat-label {
        font-size: 11px;
    }

    /* Force 2-column inline grid to stack on mobile */
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr;"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Force card grids to 1 column on mobile */
    div[style*="grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));"],
    div[style*="grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));"],
    div[style*="grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Search & Filter Toolbars */
    .search-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .search-input, select {
        width: 100% !important;
        min-width: 0 !important;
    }

    /* Make all tables horizontally scrollable without overflowing screen width */
    .data-table, .sheets-table {
        min-width: 600px;
    }

    .data-table-container,
    .sheets-grid-container {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Modals Responsive */
    .modal {
        width: 96% !important;
        max-height: 92vh !important;
        border-radius: var(--radius-sm);
        margin: 10px auto;
    }

    .modal-header {
        padding: 12px 16px;
    }

    .modal-body {
        padding: 14px;
    }

    /* Toolbar for Domain Sheet on Mobile */
    .sheets-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 10px;
    }

    .sheets-actions-left,
    .sheets-actions-right {
        width: 100%;
        flex-wrap: wrap;
        justify-content: space-between;
    }

    .sheets-grid-container {
        max-height: calc(100vh - 240px);
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .btn {
        padding: 7px 12px;
        font-size: 12px;
    }

    .top-actions #logoutBtn {
        font-size: 11px;
        padding: 4px 8px;
    }

    .sheets-pill-btn {
        padding: 4px 8px;
        font-size: 10px;
    }
}

