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

:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-surface-hover: #f1f5f9;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;
    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --transition: 150ms ease;
    --sidebar-width: 220px;
}

/* ── Dark Mode ────────────────────────────────────────────────── */
[data-theme="dark"] {
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-surface-hover: #334155;
    --color-border: #334155;
    --color-text: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-text-muted: #64748b;
    --color-danger: #ef4444;
    --color-danger-hover: #f87171;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.5);
}
[data-theme="dark"] .nav-item.active { background: rgba(59,130,246,0.15); }
[data-theme="dark"] .badge-new { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-accepted { background: #14532d; color: #86efac; }
[data-theme="dark"] .badge-denied { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .badge-in_progress { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .badge-completed { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-bug { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .badge-feature { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,0.6); }
[data-theme="dark"] .toast { background: #334155; }
[data-theme="dark"] .toast-success { background: #16a34a; }
[data-theme="dark"] .toast-error { background: var(--color-danger); }
[data-theme="dark"] .form-control:focus { box-shadow: 0 0 0 2px rgba(59,130,246,0.25); }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Inline SVG icons ────────────────────────────────────────── */
svg { vertical-align: middle; flex-shrink: 0; }

/* ── Back link ───────────────────────────────────────────────── */
.back-link { display: inline-flex; align-items: center; gap: 4px; font-size: 0.85rem; }

/* ── Layout ───────────────────────────────────────────────────── */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

.app-sidebar {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 16px 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 8px 20px 20px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-primary);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.nav-item:hover { background: var(--color-surface-hover); color: var(--color-text); text-decoration: none; }
.nav-item.active { color: var(--color-primary); background: #edf7fc; font-weight: 600; }

.nav-badge {
    background: var(--color-danger);
    color: #fff;
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: auto;
    font-weight: 600;
}

.sidebar-footer {
    padding: 8px 0;
    border-top: 1px solid var(--color-border);
    margin-top: auto;
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: all var(--transition);
}
.theme-toggle:hover { background: var(--color-surface-hover); color: var(--color-text); }

.app-main {
    padding: 24px 32px;
    max-width: 1200px;
}

/* ── Login ────────────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: 24px;
    text-align: center;
}

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 4px; font-size: 0.85rem; font-weight: 500; color: var(--color-text-secondary); }
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-surface-hover); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: var(--color-danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; }

/* ── Cards ────────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--color-border);
}
.card-body { padding: 20px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--color-border); font-weight: 600; display: flex; align-items: center; justify-content: space-between; }

/* ── Stats Cards ──────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    padding: 16px 20px;
}
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.8rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 4px; }
.stat-value.text-new { color: var(--color-primary); }
.stat-value.text-accepted { color: var(--color-success); }
.stat-value.text-progress { color: var(--color-warning); }

/* ── Tables ───────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--color-border); font-size: 0.875rem; }
.data-table th { font-weight: 600; color: var(--color-text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; background: var(--color-bg); cursor: pointer; user-select: none; white-space: nowrap; }
.data-table th:hover { color: var(--color-text); }
.data-table tbody tr { cursor: pointer; transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--color-surface-hover); }

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.badge-new { background: #ddf0fa; color: #1a6e94; }
.badge-accepted { background: #d9f5da; color: #256b27; }
.badge-denied { background: #fee2e2; color: #991b1b; }
.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-bug { background: #fee2e2; color: #991b1b; }
.badge-feature { background: #ddf0fa; color: #1a6e94; }

/* ── Page header ──────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.page-header h1 { font-size: 1.4rem; font-weight: 700; }

/* ── Filters bar ──────────────────────────────────────────────── */
.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}
.filters-bar .form-control { width: auto; min-width: 140px; }
.filters-bar input[type="search"] { min-width: 220px; }

/* ── Detail page ──────────────────────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
}
.detail-section { margin-bottom: 20px; }
.detail-section h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.detail-row { display: flex; gap: 8px; margin-bottom: 6px; font-size: 0.9rem; }
.detail-label { color: var(--color-text-muted); min-width: 120px; flex-shrink: 0; }
.detail-value { color: var(--color-text); word-break: break-word; }
.detail-description { background: var(--color-bg); padding: 12px 16px; border-radius: var(--radius-sm); margin-top: 8px; font-size: 0.9rem; white-space: pre-wrap; }

/* ── Metadata panel ───────────────────────────────────────────── */
.metadata-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
    font-size: 0.82rem;
}
.metadata-grid .detail-label { min-width: 0; color: var(--color-text-muted); }
.metadata-grid .detail-value { font-family: monospace; font-size: 0.8rem; }

/* ── Attachments ──────────────────────────────────────────────── */
.attachment-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
.attachment-item {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    width: 120px;
}
.attachment-item img { width: 120px; height: 90px; object-fit: cover; display: block; }
.attachment-item .att-name { padding: 6px; font-size: 0.7rem; color: var(--color-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment-file { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--color-bg); border-radius: var(--radius-sm); font-size: 0.82rem; }

/* ── API key display ──────────────────────────────────────────── */
.api-key-display {
    display: flex;
    align-items: center;
    gap: 8px;
}
.api-key-value {
    font-family: monospace;
    font-size: 0.82rem;
    background: var(--color-bg);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Toast ────────────────────────────────────────────────────── */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--color-text);
    color: #fff;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    box-shadow: var(--shadow-md);
    animation: slideIn 200ms ease;
}
.toast-success { background: #16a34a; }
.toast-error { background: var(--color-danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--color-border); font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--color-text-muted); padding: 4px; display: flex; align-items: center; }
.modal-close:hover { color: var(--color-text); }

/* ── Pagination ───────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}
.pagination-buttons { display: flex; gap: 4px; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--color-text-muted);
}
.empty-state h3 { font-size: 1.1rem; margin-bottom: 8px; color: var(--color-text-secondary); }

/* ── Mobile header (hidden on desktop) ────────────────────────── */
.mobile-header {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* ── Mobile header bar ── */
    .mobile-header {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .mobile-brand {
        font-size: 1.05rem;
        font-weight: 700;
        color: var(--color-primary);
    }

    .hamburger-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        padding: 0;
        background: none;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-sm);
        cursor: pointer;
        color: var(--color-text);
    }

    /* ── Sidebar as slide-out drawer ── */
    .app-layout {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        position: relative;
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 250ms ease;
    }

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

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 1000;
        opacity: 0;
        pointer-events: none;
        transition: opacity 250ms ease;
    }

    .sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    /* ── Main content ── */
    .app-main {
        padding: 16px;
        max-width: 100%;
        overflow-x: hidden;
        flex: 1;
    }

    /* ── Page headers ── */
    .page-header {
        flex-wrap: wrap;
        gap: 10px;
    }
    .page-header h1 {
        font-size: 1.2rem;
    }

    /* ── Stats grid ── */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .stat-card {
        padding: 12px 14px;
    }
    .stat-value {
        font-size: 1.4rem;
    }

    /* ── Tables: horizontal scroll ── */
    .card {
        overflow: visible;
    }
    .data-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .data-table th,
    .data-table td {
        padding: 8px 12px;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* ── Feedback detail ── */
    .detail-grid {
        grid-template-columns: 1fr;
    }
    .detail-row {
        flex-direction: column;
        gap: 2px;
    }
    .detail-label {
        min-width: 0;
        font-size: 0.78rem;
    }

    /* ── Metadata grid ── */
    .metadata-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* ── Filters bar ── */
    .filters-bar {
        flex-direction: column;
    }
    .filters-bar .form-control,
    .filters-bar input[type="search"] {
        width: 100%;
        min-width: unset;
    }

    /* ── Modals ── */
    .modal-overlay {
        align-items: flex-end;
    }
    .modal {
        max-width: 100%;
        max-height: 92vh;
        border-radius: var(--radius) var(--radius) 0 0;
    }

    /* ── Button groups ── */
    .btn-group {
        flex-wrap: wrap;
    }

    /* ── Login page ── */
    .login-card {
        margin: 16px;
        padding: 24px;
    }

    /* ── Pagination ── */
    .pagination {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    /* ── Toast ── */
    .toast-container {
        left: 16px;
        right: 16px;
    }
    .toast {
        text-align: center;
    }

    /* ── API key display ── */
    .api-key-display {
        flex-wrap: wrap;
    }
    .api-key-value {
        max-width: 140px;
        font-size: 0.75rem;
    }

    /* ── Attachment grid ── */
    .attachment-grid {
        gap: 8px;
    }
    .attachment-item {
        width: 100px;
    }
    .attachment-item img {
        width: 100px;
        height: 75px;
    }
}

/* ── Small phones ── */
@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .stat-value {
        font-size: 1.2rem;
    }
    .app-main {
        padding: 12px;
    }
    .card-body {
        padding: 14px;
    }
    .card-header {
        padding: 12px 14px;
        font-size: 0.9rem;
    }
}
