/* =====================================================
   MagicCloud BI Portal — Shared Base Styles
   Override --brand-primary and --brand-accent per customer
   ===================================================== */

:root {
    --brand-primary: #667eea;
    --brand-accent: #764ba2;
    --bg-body: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-accent) 100%);
    --bg-card: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-light: #dddddd;
    --bg-soft: #f8f9fa;
    --green: #10b981;
    --red: #ef4444;
    --amber: #f59e0b;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-body);
    min-height: 100vh;
    padding: 16px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
.header {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-logo {
    height: 40px;
    width: auto;
}

.header-text h1 {
    color: var(--text-primary);
    font-size: 22px;
    margin-bottom: 4px;
}

.header-text p {
    color: var(--text-secondary);
    font-size: 12px;
}

.header-spacer {
    flex: 1;
}

.powered-by {
    color: var(--text-muted);
    font-size: 9px;
    text-align: right;
}

/* Stat Cards */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    padding: 14px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    text-align: center;
    transition: transform 0.15s, box-shadow 0.15s;
}

.stat-card[style*="cursor: pointer"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.stat-card h3 {
    color: var(--brand-primary);
    font-size: 22px;
    margin-bottom: 4px;
}

.stat-card p {
    color: var(--text-secondary);
    font-size: 10px;
}

/* Query Section */
.query-section {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-bottom: 16px;
}

.quick-queries {
    margin-bottom: 14px;
}

.quick-queries h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 11px;
}

.quick-query-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.quick-query-btn {
    background: var(--bg-soft);
    border: 2px solid var(--border-light);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 10px;
    color: var(--text-primary);
}

.quick-query-btn:hover {
    background: var(--brand-primary);
    color: white;
    border-color: var(--brand-primary);
}

.input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

input[type="text"] {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid var(--border-light);
    border-radius: 8px;
    font-size: 12px;
    transition: border-color 0.3s;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--brand-primary);
}

.btn-primary {
    background: var(--brand-primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    transition: opacity 0.3s;
    font-weight: 600;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* Loading */
.loading {
    text-align: center;
    padding: 14px;
    color: var(--brand-primary);
    font-weight: 600;
    font-size: 12px;
}

.loading-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.loading-progress-bar {
    width: 100%;
    max-width: 360px;
    height: 6px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.loading-progress-bar::before {
    content: "";
    position: absolute;
    top: 0;
    left: -40%;
    width: 40%;
    height: 100%;
    background: var(--brand-primary);
    border-radius: 3px;
    animation: loading-slide 1.2s ease-in-out infinite;
}

@keyframes loading-slide {
    0% { left: -40%; }
    100% { left: 100%; }
}

.loading-cancel-btn {
    background: #fff;
    border: 1px solid #cbd5e1;
    color: #475569;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.loading-cancel-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #1e293b;
}

/* Slicer buttons */
.slicer-btn {
    display: inline-block;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    line-height: 16px;
}

.slicer-btn:hover {
    border-color: var(--brand-primary, #3b82f6);
    color: var(--brand-primary, #3b82f6);
}

.slicer-btn.active {
    background: var(--brand-primary, #3b82f6);
    border-color: var(--brand-primary, #3b82f6);
    color: #fff;
}

.slicer-label {
    font-size: 9px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-right: 4px;
}

/* Results */
.results-section {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-bottom: 16px;
}

.results-section h2 {
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 12px;
}

.results-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-soft);
    border-radius: 6px;
    font-size: 11px;
}

.results-meta span { color: var(--text-secondary); }
.results-meta .cost { color: var(--brand-primary); font-weight: 600; }

.sql-display {
    background: var(--bg-soft);
    padding: 10px;
    border-radius: 6px;
    border-left: 3px solid var(--brand-primary);
    margin-bottom: 12px;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    overflow-x: auto;
    white-space: pre-wrap;
}

.action-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.btn-secondary {
    background: var(--bg-soft);
    border: 2px solid var(--border-light);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.3s;
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--brand-primary);
    color: white;
    border-color: var(--brand-primary);
}

.btn-success {
    background: var(--green);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    transition: opacity 0.3s;
}

.btn-success:hover { opacity: 0.9; }

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    font-size: 11px;
}

thead { background: var(--brand-primary); color: white; }

th, td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

tbody tr:hover { background: var(--bg-soft); }

.no-results {
    text-align: center;
    padding: 28px;
    color: var(--text-muted);
    font-size: 11px;
}

.error {
    background: #fee2e2;
    color: #dc2626;
    padding: 10px;
    border-radius: 6px;
    border-left: 3px solid #dc2626;
    margin-top: 12px;
    font-size: 11px;
}

/* History */
.history-section {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-bottom: 16px;
}

.history-section h2 {
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 12px;
}

.history-list {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 8px;
}

.history-item {
    background: var(--bg-soft);
    padding: 8px 10px;
    border-radius: 6px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.history-item:hover { background: #e9ecef; }
.history-query { flex: 1; color: var(--text-primary); font-size: 10px; }
.history-timestamp { color: var(--text-muted); font-size: 8px; margin-top: 2px; }

.history-buttons { display: flex; gap: 4px; }

.history-btn {
    padding: 3px 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 9px;
    transition: opacity 0.3s;
    color: white;
}

.history-btn.run { background: var(--brand-primary); }
.history-btn.edit { background: var(--amber); }
.history-btn.delete { background: var(--red); }
.history-btn:hover { opacity: 0.8; }

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-card {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card .login-logo {
    height: 60px;
    margin-bottom: 16px;
}

.login-card h2 {
    color: var(--text-primary);
    font-size: 20px;
    margin-bottom: 4px;
}

.login-card .login-subtitle {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 24px;
}

.login-card .form-group {
    margin-bottom: 14px;
    text-align: left;
}

.login-card label {
    display: block;
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 4px;
    font-weight: 600;
}

.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border-light);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.login-card input:focus {
    outline: none;
    border-color: var(--brand-primary);
}

.login-card .btn-login {
    width: 100%;
    background: var(--brand-primary);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.3s;
    margin-top: 8px;
}

.login-card .btn-login:hover { opacity: 0.9; }
.login-card .btn-login:disabled { opacity: 0.5; cursor: not-allowed; }

.login-error {
    background: #fee2e2;
    color: #dc2626;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    margin-bottom: 12px;
}

.login-powered {
    color: var(--text-muted);
    font-size: 9px;
    margin-top: 20px;
}

/* User info in header */
.user-info {
    color: var(--text-muted);
    font-size: 11px;
}

.btn-logout {
    background: none;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-logout:hover {
    border-color: var(--red);
    color: var(--red);
}

/* =====================================================
   RESULTS POPUP MODAL
   ===================================================== */
.results-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.results-modal {
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    width: 95vw;
    max-width: 1400px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.results-modal-header h2 {
    font-size: 16px;
    color: var(--text-primary);
    margin: 0;
}

.results-modal-meta {
    display: flex;
    gap: 16px;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

.results-modal-meta .cost {
    color: var(--brand-primary);
    font-weight: 600;
}

.results-modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
    line-height: 1;
}

.results-modal-close:hover {
    color: var(--red);
}

.results-modal-toolbar {
    display: flex;
    gap: 8px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-light);
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.results-modal-toolbar input {
    padding: 6px 10px;
    border: 1px solid var(--border-light);
    border-radius: 5px;
    font-size: 12px;
    width: 250px;
}

.results-modal-toolbar input:focus {
    outline: none;
    border-color: var(--brand-primary);
}

.results-modal-body {
    flex: 1;
    padding: 0;
    overflow: hidden;
    min-height: 300px;
    position: relative;
}

.results-modal-body .ag-theme-alpine {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* Score circles (used by player dashboard drill-down + eclectic grid) */
.dash-drill-score {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
    margin: 3px;
}

.dash-drill-birdie { background: #dcfce7; color: #166534; }
.dash-drill-par { background: #f0f9ff; color: #0369a1; }
.dash-drill-bogey { background: #fef9c3; color: #854d0e; }
.dash-drill-double { background: #fef2f2; color: #991b1b; }

@media (max-width: 480px) {
    .dash-drill-score { width: 28px; height: 28px; font-size: 12px; margin: 2px; }
}

/* Header text wrapping — don't break words */
.ag-header-cell-label .ag-header-cell-text {
    white-space: normal !important;
    word-break: keep-all !important;
    overflow-wrap: break-word !important;
    line-height: 1.3;
    text-overflow: unset !important;
}

.results-modal-sql {
    padding: 10px 20px;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    max-height: 120px;
    overflow-y: auto;
}

.results-modal-sql pre {
    background: var(--bg-soft);
    padding: 8px 12px;
    border-radius: 6px;
    border-left: 3px solid var(--brand-primary);
    font-family: 'Courier New', monospace;
    font-size: 11px;
    white-space: pre-wrap;
    margin: 0;
}

/* =====================================================
   RESPONSIVE — Tablet (768px and below)
   ===================================================== */
@media (max-width: 768px) {
    body { padding: 10px; }

    .header {
        flex-wrap: wrap;
        padding: 14px;
        gap: 10px;
    }

    .header-logo { height: 35px; }

    .header-text h1 { font-size: 18px; }
    .header-text p { font-size: 11px; }

    .stats {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .stat-card { padding: 10px; min-width: unset !important; }
    .stat-card h3 { font-size: 18px; }
    .stat-card p { font-size: 10px; }

    .header {
        flex-wrap: wrap;
        gap: 6px;
        padding: 12px !important;
    }
    .header-text h1 { font-size: 16px !important; }
    .header-text p { font-size: 10px !important; }
    .powered-by { font-size: 9px !important; }
    .user-info { font-size: 12px !important; }
    .btn-logout { font-size: 10px !important; padding: 3px 8px !important; }

    .query-section,
    .results-section,
    .history-section {
        padding: 14px;
    }

    .quick-query-buttons { gap: 5px; }
    .quick-query-btn { font-size: 11px; padding: 6px 10px; }

    .input-group {
        flex-direction: column;
    }

    .input-group input[type="text"] {
        width: 100%;
    }

    .btn-primary {
        width: 100%;
        text-align: center;
    }

    table { font-size: 11px; }
    th, td { padding: 6px 8px; }

    .results-meta { flex-direction: column; gap: 4px; text-align: center; }

    .action-buttons { justify-content: center; }

    .login-card { padding: 24px; margin: 0 10px; }
}

/* =====================================================
   RESPONSIVE — Phone (480px and below)
   ===================================================== */
@media (max-width: 480px) {
    body { padding: 6px; }

    .container { max-width: 100%; }

    .header {
        flex-direction: column;
        text-align: center;
        padding: 12px;
    }

    .header-spacer { display: none; }

    .header-text h1 { font-size: 16px; }
    .header-text p { font-size: 10px; }

    .stats {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .stat-card h3 { font-size: 16px; }
    .stat-card { min-width: unset !important; }

    .quick-query-buttons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 4px;
    }

    .quick-query-btn {
        width: 100%;
        text-align: center;
    }

    .history-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .history-buttons {
        align-self: flex-end;
    }

    /* Make results table horizontally scrollable */
    #resultsTable {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table { min-width: 500px; }

    .login-card {
        padding: 20px 16px;
        margin: 0 4px;
        border-radius: 8px;
    }

    .login-card h2 { font-size: 18px; }
}

.hidden { display: none; }
