/* ══════════════════════════════════════════
   Gemini File Search RAG — Premium Dark Theme
   ══════════════════════════════════════════ */

:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #0f0f2a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.07);
    --glass-bg: rgba(15, 15, 42, 0.85);
    --glass-border: rgba(255, 255, 255, 0.08);
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.06);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ── Glassmorphism ── */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
}

/* ── 기본 요소 ── */
.view {
    display: none;
    height: 100vh;
}

.view.active {
    display: flex;
    flex-direction: column;
}

.main-view {
    display: none;
    flex: 1;
    overflow: hidden;
}

.main-view.active {
    display: flex;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-light);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-accent {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-light);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.btn-accent:hover {
    background: rgba(99, 102, 241, 0.25);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
}

input,
textarea,
select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    padding: 10px 14px;
    width: 100%;
    transition: var(--transition);
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

.input-group {
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.error-msg {
    color: var(--danger);
    font-size: 13px;
    margin-top: 10px;
    min-height: 20px;
}

.result-msg {
    font-size: 13px;
    margin-top: 10px;
    min-height: 20px;
}

.muted {
    color: var(--text-muted);
    font-size: 13px;
}

/* ── Auth View ── */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #1a1040 50%, var(--bg-primary) 100%);
}

.auth-card {
    width: 420px;
    max-width: 95vw;
    padding: 40px;
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.auth-logo {
    text-align: center;
    margin-bottom: 30px;
}

.auth-logo .logo-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.auth-logo h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 6px;
}

.auth-logo .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.tab.active {
    background: var(--accent);
    color: #fff;
}

.tab:hover:not(.active) {
    color: var(--text-primary);
}

.auth-hint {
    text-align: center;
    margin-top: 16px;
    color: var(--text-muted);
    font-size: 12px;
}

/* ── Navbar ── */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 60px;
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-logo {
    font-size: 24px;
}

.nav-title {
    font-size: 16px;
    font-weight: 600;
}

.nav-center {
    display: flex;
    gap: 4px;
}

.nav-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.nav-tab.active {
    background: var(--accent);
    color: #fff;
}

.nav-tab:hover:not(.active) {
    background: var(--bg-card);
    color: var(--text-primary);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.credit-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(168, 85, 247, 0.2));
    border: 1px solid rgba(99, 102, 241, 0.3);
    font-size: 14px;
    font-weight: 600;
}

.user-name {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ── Chat Layout ── */
.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 60px);
}

.sidebar {
    width: 300px;
    min-width: 300px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 16px;
}

.sidebar-section {
    margin-bottom: 20px;
}

.sidebar-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.store-list,
.session-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.store-item,
.session-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.store-item:hover,
.session-item:hover {
    background: var(--bg-card-hover);
}

.store-item.active,
.session-item.active {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.store-item .store-meta,
.session-item .session-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* 고급 설정 */
.chunk-settings {
    margin-top: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.chunk-settings summary {
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    margin-bottom: 8px;
}

.chunk-settings .input-group {
    margin-bottom: 8px;
}

.chunk-settings .input-group label {
    font-size: 11px;
}

/* 저장소 설정 상자 */
.store-settings-area {
    margin: 15px 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
}

.store-settings-area label {
    font-size: 11px;
    color: var(--accent);
    font-weight: 600;
    display: block;
    margin-bottom: 5px;
}

.store-settings-area textarea {
    width: 100%;
    height: 80px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
    padding: 5px;
    resize: none;
    margin-bottom: 5px;
}

/* 파일 업로드 */
.upload-area {
    margin-top: 8px;
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 16px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.upload-label:hover {
    border-color: var(--accent);
    color: var(--accent-light);
}

#file-input {
    display: none;
}

.file-list {
    margin-top: 8px;
    font-size: 12px;
}

.file-item {
    padding: 4px 0;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

/* 사용량 */
.usage-stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.stat-label {
    color: var(--text-muted);
}

.stat-value {
    font-weight: 600;
    color: var(--accent-light);
}

/* ── Chat Main ── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-msg {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    color: var(--text-secondary);
}

.welcome-msg h2 {
    font-size: 28px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.welcome-msg p {
    font-size: 16px;
    margin-bottom: 24px;
}

.welcome-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.step {
    padding: 12px 24px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-secondary);
}

.msg {
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

.msg-user {
    align-self: flex-end;
}

.msg-assistant {
    align-self: flex-start;
}

.msg-bubble {
    padding: 14px 18px;
    border-radius: 16px;
    line-height: 1.6;
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-user .msg-bubble {
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-assistant .msg-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    padding: 0 4px;
}

.msg-citations {
    margin-top: 8px;
    padding: 10px 14px;
    background: rgba(99, 102, 241, 0.08);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(99, 102, 241, 0.15);
    font-size: 12px;
}

.msg-citations summary {
    cursor: pointer;
    color: var(--accent-light);
    font-weight: 500;
}

.citation-item {
    padding: 4px 0;
    color: var(--text-secondary);
}

.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 16px;
}

.chat-input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 6px 0;
}

.chat-input-wrapper textarea:focus {
    box-shadow: none;
}

.btn-send {
    padding: 10px 20px;
    border-radius: 12px;
}

.input-hint {
    display: block;
    text-align: center;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 11px;
}

/* 로딩 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* ── Admin ── */
.admin-layout {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.admin-header {
    margin-bottom: 24px;
}

.admin-header h2 {
    font-size: 24px;
    margin-bottom: 16px;
}

.admin-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.admin-tab {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.admin-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.admin-tab:hover:not(.active) {
    background: var(--bg-card-hover);
}

.admin-panel {
    display: none;
}

.admin-panel.active {
    display: block;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.dash-card {
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
}

.dash-card .dash-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-light);
}

.dash-card .dash-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 6px;
}

.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: 12px;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.data-table tr:hover td {
    background: var(--bg-card);
}

.credit-grant-form {
    padding: 24px;
    border-radius: var(--radius);
    margin-bottom: 24px;
}

.credit-grant-form h3 {
    margin-bottom: 16px;
}

.form-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-row .input-group {
    flex: 1;
    min-width: 150px;
}

.form-row .btn {
    margin-bottom: 16px;
}

.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
}

.filter-bar select {
    width: auto;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.badge-active {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.badge-closed,
.badge-inactive {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.badge-admin {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-light);
}

.badge-deleted {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    width: 480px;
    max-width: 95vw;
    max-height: 80vh;
    border-radius: var(--radius);
    padding: 0;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 18px;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: 60vh;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    min-width: 250px;
    max-width: 400px;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
    box-shadow: var(--shadow);
}

.toast-success {
    background: rgba(16, 185, 129, 0.9);
    color: #fff;
}

.toast-error {
    background: rgba(239, 68, 68, 0.9);
    color: #fff;
}

.toast-info {
    background: rgba(99, 102, 241, 0.9);
    color: #fff;
}

/* ── Animations ── */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: auto;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .chat-layout {
        flex-direction: column;
    }

    .navbar {
        padding: 0 12px;
    }

    .nav-title {
        display: none;
    }
}