/* ============================================================
   Delta Metrics Internal Dashboard
   Dark navy theme with sidebar navigation
   ============================================================ */

:root {
    --bg-deep:    #0A0F1A;
    --bg-base:    #0D1B2A;
    --bg-surface: #1B2838;
    --bg-raised:  #243447;
    --bg-hover:   #2C3E50;

    --border:     rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.12);

    --text:       rgba(255, 255, 255, 0.92);
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.38);

    --accent:     #0D3B54;
    --accent-bright: #1A6B8A;
    --accent-text: #4ECDC4;

    --blue:       #6495ED;
    --green:      #22C55E;
    --yellow:     #EAB308;
    --red:        #EF4444;
    --purple:     #A78BFA;
    --orange:     #F97316;
    --cyan:       #4ECDC4;

    --font:       'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --mono:       'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

    --sidebar-width: 240px;
    --header-height: 56px;

    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  14px;

    --shadow:     0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg:  0 8px 32px rgba(0, 0, 0, 0.5);
}

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

html { font-size: 14px; }

body {
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---- App Layout ---- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-base);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px 18px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-brand {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sidebar-env {
    display: inline-block;
    margin-top: 6px;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-text);
    background: rgba(78, 205, 196, 0.12);
    padding: 2px 8px;
    border-radius: 4px;
}

.sidebar-app-selector {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
}

.sidebar-app-selector select {
    width: 100%;
    padding: 7px 10px;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.sidebar-nav {
    list-style: none;
    padding: 8px 10px;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 2px;
}

.nav-link:hover {
    background: var(--bg-surface);
    color: var(--text);
}

.nav-link.active {
    background: var(--accent);
    color: #fff;
}

.nav-link svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-link.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid var(--border);
}

.sidebar-back-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.82rem;
    transition: color 0.15s;
}

.sidebar-back-link:hover {
    color: var(--text);
}

/* ---- Mobile header ---- */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 90;
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 4px;
}

.mobile-title {
    font-weight: 600;
    font-size: 1rem;
}

/* ---- Main Content ---- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    padding: 0 32px 40px;
}

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

.content-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.section-subtitle {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-top: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-timestamp {
    font-size: 0.75rem;
    font-family: var(--mono);
    color: var(--text-muted);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent-bright);
    color: #fff;
}

.btn-primary:hover { background: #1E7DA0; }

.btn-secondary {
    background: var(--bg-raised);
    color: var(--text);
    border: 1px solid var(--border-light);
}

.btn-secondary:hover { background: var(--bg-hover); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

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

.btn-sm {
    padding: 4px 10px;
    font-size: 0.78rem;
}

.btn-success { background: rgba(34, 197, 94, 0.2); color: var(--green); border: 1px solid rgba(34, 197, 94, 0.3); }
.btn-success:hover { background: rgba(34, 197, 94, 0.3); }

.btn-danger { background: rgba(239, 68, 68, 0.2); color: var(--red); border: 1px solid rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.3); }

.btn-warning { background: rgba(234, 179, 8, 0.2); color: var(--yellow); border: 1px solid rgba(234, 179, 8, 0.3); }
.btn-warning:hover { background: rgba(234, 179, 8, 0.3); }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

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

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

/* ---- Cards ---- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

/* ---- Stats Grid ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stats-grid-small {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: border-color 0.15s;
}

.stat-card:hover {
    border-color: var(--border-light);
}

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

.stat-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ---- Tables ---- */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table thead th {
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--bg-surface);
}

.data-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 0 4px;
}

.table-pagination .btn {
    min-width: 36px;
    justify-content: center;
}

/* ---- Search / Toolbar ---- */
.section-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    flex: 1;
    min-width: 200px;
}

.search-box svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.88rem;
    padding: 9px 0;
    width: 100%;
    outline: none;
}

.search-box input::placeholder { color: var(--text-muted); }

.filter-group {
    display: flex;
    gap: 8px;
}

.filter-group select {
    padding: 8px 30px 8px 10px;
    font-family: var(--font);
    font-size: 0.85rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

/* ---- Sections ---- */
.section { animation: fadeIn 0.2s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.hidden { display: none !important; }

.section-note {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.6;
    max-width: 640px;
}

/* ---- Badges / Tags ---- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-solo   { background: rgba(100, 149, 237, 0.2); color: var(--blue); }
.badge-debate { background: rgba(249, 115, 22, 0.2);  color: var(--orange); }
.badge-panel  { background: rgba(167, 139, 250, 0.2); color: var(--purple); }
.badge-public { background: rgba(34, 197, 94, 0.15);  color: var(--green); }
.badge-private{ background: rgba(255, 255, 255, 0.08); color: var(--text-muted); }

.badge-approved { background: rgba(34, 197, 94, 0.2); color: var(--green); }
.badge-pending  { background: rgba(234, 179, 8, 0.2); color: var(--yellow); }
.badge-rejected { background: rgba(239, 68, 68, 0.2); color: var(--red); }

.tag-chip {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.7rem;
    background: rgba(78, 205, 196, 0.12);
    color: var(--accent-text);
    margin: 1px 2px;
}

.truncate-id {
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
}

.truncate-id:hover {
    color: var(--text);
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal {
    background: var(--bg-base);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-base);
    z-index: 1;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-body {
    padding: 20px 24px;
}

.modal-field {
    margin-bottom: 16px;
}

.modal-field-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.modal-field-value {
    font-size: 0.88rem;
    color: var(--text);
    line-height: 1.5;
}

.modal-field-value pre {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-family: var(--mono);
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

.modal-field-value a {
    color: var(--accent-text);
    text-decoration: none;
}

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

.modal-cover-image {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

/* ---- Image Gallery ---- */
.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.image-gallery-item {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 16/10;
    background: var(--bg-raised);
}

.image-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.image-gallery-item:hover img {
    transform: scale(1.05);
}

.image-gallery-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px 8px 6px;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    font-size: 0.7rem;
    color: rgba(255,255,255,0.8);
}

.image-gallery-source {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
}

.source-unsplash { background: rgba(255, 255, 255, 0.15); }
.source-supabase { background: rgba(78, 205, 196, 0.3); color: var(--accent-text); }

/* ---- Analytics Charts ---- */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.card-wide {
    grid-column: 1 / -1;
}

.overview-charts {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

/* ---- Config (System) ---- */
.config-row {
    margin-bottom: 12px;
}

.config-row label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 500;
}

.config-row input {
    width: 100%;
    padding: 9px 12px;
    font-family: var(--mono);
    font-size: 0.85rem;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
}

.config-row input::placeholder { color: var(--text-muted); }

.config-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.code-block {
    font-family: var(--mono);
    font-size: 0.8rem;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-secondary);
    max-height: 300px;
    overflow-y: auto;
}

.pages-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.page-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
}

.page-chip.ok      { background: rgba(34, 197, 94, 0.15);  color: var(--green); }
.page-chip.error   { background: rgba(239, 68, 68, 0.15);  color: var(--red); }
.page-chip.pending { background: rgba(255,255,255,0.06);    color: var(--text-muted); }

/* ---- System status ---- */
.status-grid-inline {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.status-item-inline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-raised);
    border-radius: var(--radius-sm);
}

.status-item-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.status-badge-inline {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
}

.status-badge-inline.ok    { background: rgba(34, 197, 94, 0.2); color: var(--green); }
.status-badge-inline.error { background: rgba(239, 68, 68, 0.2); color: var(--red); }
.status-badge-inline.warn  { background: rgba(234, 179, 8, 0.2); color: var(--yellow); }

/* ---- Toast ---- */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-raised);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    font-size: 0.85rem;
    color: var(--text);
    box-shadow: var(--shadow);
    animation: toastIn 0.25s ease, toastOut 0.25s ease 2.75s forwards;
    max-width: 360px;
}

.toast.toast-error { border-left: 3px solid var(--red); }
.toast.toast-success { border-left: 3px solid var(--green); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(8px); }
}

/* ---- Text utilities ---- */
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.text-yellow { color: var(--yellow); }

/* ---- Loading spinner ---- */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-light);
    border-top-color: var(--accent-text);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-row td {
    text-align: center;
    padding: 40px 12px;
    color: var(--text-muted);
}

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    opacity: 0.3;
    margin-bottom: 12px;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .analytics-grid {
        grid-template-columns: 1fr;
    }

    .overview-charts {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding: 0 16px 32px;
        padding-top: var(--header-height);
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }

    .stat-card {
        padding: 14px 16px;
    }

    .stat-icon { display: none; }

    .content-header h1 {
        font-size: 1.3rem;
    }

    .section-toolbar {
        flex-direction: column;
    }

    .search-box {
        width: 100%;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group select {
        flex: 1;
    }

    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ---- Moderation actions row ---- */
.mod-actions {
    display: flex;
    gap: 4px;
}

.moderation-header-row {
    margin-bottom: 8px;
}

/* ---- User link ---- */
.user-link {
    color: var(--accent-text);
    text-decoration: none;
    cursor: pointer;
}

.user-link:hover {
    text-decoration: underline;
}
