/* ==========================================================================
   UGC Dashboard — Shared Styles
   Dark theme, sidebar layout, pure CSS
   ========================================================================== */

/* ---------- Custom Properties ---------- */
:root {
    --bg: #0a0a0a;
    --bg-card: #141414;
    --bg-card-hover: #1a1a1a;
    --bg-input: #1a1a1a;
    --bg-sidebar: #0f0f0f;
    --border: #222;
    --border-focus: #555;
    --text: #e5e5e5;
    --text-white: #fff;
    --text-muted: #888;
    --text-dim: #666;
    --text-label: #999;
    --green: #22c55e;
    --green-bg: #052e16;
    --green-border: rgba(34, 197, 94, 0.2);
    --red: #ef4444;
    --red-bg: #dc2626;
    --red-hover: #b91c1c;
    --red-border: rgba(239, 68, 68, 0.3);
    --yellow: #eab308;
    --yellow-bg: #422006;
    --blue: #3b82f6;
    --primary: #3b82f6;
    --blue-bg: #1e3a5f;
    --sidebar-w: 240px;
    --radius: 6px;
    --radius-lg: 8px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Scrollbar — webkit */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}

/* ---------- Utility ---------- */
.hidden {
    display: none !important;
}

/* ---------- Layout ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.main-content {
    margin-left: var(--sidebar-w);
    padding: 40px 48px;
    min-height: 100vh;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
}

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 12px;
    left: 12px;
    width: 44px;
    height: 44px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    z-index: 60;
    font-size: 18px;
    line-height: 1;
}

/* ---------- Sidebar Internals ---------- */
.sidebar-logo {
    padding: 24px 20px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text-white);
}

.sidebar-logo .logo-accent {
    color: var(--blue);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-section {
    margin-bottom: 8px;
}

.sidebar-section-title {
    text-transform: uppercase;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    padding: 8px 20px 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    font-size: 13px;
    color: var(--text-muted);
    border-left: 2px solid transparent;
    transition: all 0.15s;
    cursor: pointer;
}

.sidebar-link:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.03);
}

.sidebar-link.active {
    color: var(--text-white);
    border-left-color: var(--blue);
    background: rgba(59, 130, 246, 0.08);
}

.sidebar-link svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.6;
}

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

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

.sidebar-org-name {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-signout {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 0;
    margin-top: 4px;
    font-family: var(--font);
}

.sidebar-signout:hover {
    color: var(--red);
}

/* ---------- Page Structure ---------- */
.page-header {
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-white);
    margin: 0 0 4px;
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0;
}

.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-white);
}

/* ---------- Stats ---------- */
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
}

.stat-value {
    font-size: 13px;
    color: var(--text-white);
    font-weight: 500;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.stat-card-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-card-value {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-white);
}

/* ---------- Tables ---------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    font-size: 13px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

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

/* ---------- Forms ---------- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-label);
    margin-bottom: 6px;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    box-sizing: border-box;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--border-focus);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

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

.btn-primary {
    background: #fff;
    color: #000;
}

.btn-primary:hover {
    background: #e5e5e5;
}

.btn-secondary {
    background: #222;
    color: #fff;
}

.btn-secondary:hover {
    background: #333;
}

.btn-danger {
    background: var(--red-bg);
    color: #fff;
}

.btn-danger:hover {
    background: var(--red-hover);
}

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

.btn:active {
    transform: scale(0.97);
}

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

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.badge-active {
    background: var(--green-bg);
    color: var(--green);
}

.badge-inactive {
    background: #1c1917;
    color: #a8a29e;
}

.badge-pending {
    background: var(--yellow-bg);
    color: var(--yellow);
}

.badge-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--red);
}

/* ---------- Key Display ---------- */
.key-value {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--green);
    background: var(--green-bg);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    word-break: break-all;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    color: #fff;
    background: #22c55e;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    z-index: 1000;
    max-width: calc(100vw - 32px);
}

.toast.show {
    opacity: 1;
}

.toast.error {
    background: var(--red);
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-white);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 20px;
}

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

.modal-lg {
    max-width: 600px;
}

/* ---------- Form Enhancements ---------- */
.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

.form-section {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 20px 0 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.form-required {
    color: var(--red);
    font-weight: 400;
}

.form-note {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 16px;
    line-height: 1.5;
}

.advanced-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    padding: 12px 0;
    margin-top: 4px;
    user-select: none;
}

.advanced-toggle:hover {
    color: var(--text);
}

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

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

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

/* ---------- Loading ---------- */
.loading {
    opacity: 0.5;
    pointer-events: none;
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ---------- Inline Style Replacements ---------- */

.actions-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.mono-id {
    font-family: var(--font-mono);
    font-size: 12px;
}

/* ---------- Shared Component Styles ---------- */

.actions-cell {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.result-block {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    font-size: 13px;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font-mono);
    max-height: 300px;
    overflow-y: auto;
}

.confirm-text {
    font-size: 14px;
    color: var(--text);
    line-height: 1.6;
}

.confirm-text strong {
    color: var(--text-white);
}

.danger-confirm {
    color: var(--red);
    font-weight: 500;
}

/* ---------- Focus Visible ---------- */
:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

/* ---------- Sidebar Active State ---------- */
.sidebar-link:active {
    background: var(--bg-hover, rgba(255, 255, 255, 0.05));
}

/* ---------- Placeholder ---------- */
::placeholder {
    color: var(--text-dim);
    opacity: 1;
}

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

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

    .sidebar-toggle {
        display: flex;
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 60px 16px 20px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .sidebar-link {
        padding: 12px 20px;
    }

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

    .toast {
        bottom: calc(env(safe-area-inset-bottom, 24px) + 24px);
    }

    .modal {
        max-height: 90vh;
    }

    /* --- Responsive tables: stacked card layout --- */
    .data-table thead {
        display: none;
    }

    .data-table tbody tr {
        display: block;
        padding: 12px;
        margin-bottom: 8px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }

    .data-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 4px 0;
        border: none;
    }

    .data-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 12px;
        margin-right: 12px;
        flex-shrink: 0;
    }

    .actions-cell {
        flex-direction: column;
        width: 100%;
        padding-top: 8px;
        border-top: 1px solid var(--border);
        margin-top: 4px;
    }

    .actions-cell .btn {
        width: 100%;
        justify-content: center;
    }
}
