/* ==================== Variables CSS ==================== */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(20, 20, 30, 0.8);
    --bg-card-hover: rgba(30, 30, 45, 0.9);

    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #6b6b7b;

    --accent-primary: #6366f1;
    --accent-primary-hover: #4f46e5;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-radius: 12px;
    --border-radius-lg: 16px;
    --border-radius-sm: 8px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background gradient */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.1) 0%, transparent 40%);
    pointer-events: none;
    z-index: -1;
}

/* ==================== App Container ==================== */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

/* ==================== Header ==================== */
.header {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 30px;
}

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

.logo svg {
    color: var(--accent-primary);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-tabs {
    display: flex;
    gap: 8px;
    padding: 6px;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.nav-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
    color: var(--text-primary);
    background: var(--accent-gradient);
    box-shadow: var(--shadow-glow);
}

.nav-tab svg {
    flex-shrink: 0;
}

/* ==================== Cards ==================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    backdrop-filter: blur(10px);
    transition: all var(--transition-normal);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.card h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

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

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

/* ==================== Tab Content ==================== */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== Search Section ==================== */
.search-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.search-card {
    text-align: center;
}

.search-form {
    max-width: 500px;
    margin: 0 auto;
}

.input-group {
    display: flex;
    gap: 12px;
}

.input-group input {
    flex: 1;
}

input[type="text"] {
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all var(--transition-normal);
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

input[type="text"]::placeholder {
    color: var(--text-muted);
}

/* ==================== Buttons ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.85rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ==================== Result Section ==================== */
.result-container,
.error-container {
    max-width: 600px;
    margin: 0 auto;
}

.result-card {
    text-align: left;
}

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

.result-header h3 {
    margin-bottom: 0;
}

.badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge.cache {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.badge.api {
    background: rgba(59, 130, 246, 0.2);
    color: var(--info);
}

.result-content {
    display: grid;
    gap: 16px;
}

.result-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.result-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-value {
    font-size: 1.1rem;
    font-weight: 500;
}

.error-card {
    text-align: center;
    padding: 40px;
}

.error-card svg {
    color: var(--error);
    margin-bottom: 16px;
}

.error-card p {
    color: var(--text-secondary);
}

/* ==================== Tokens Section ==================== */
.tokens-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.tokens-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

.token-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    transition: all var(--transition-normal);
}

.token-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.token-info {
    flex: 1;
}

.token-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.token-value {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--text-muted);
    word-break: break-all;
}

.token-meta {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.token-actions {
    display: flex;
    gap: 8px;
}

.token-status {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.token-status.active {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.token-status.inactive {
    background: rgba(239, 68, 68, 0.2);
    color: var(--error);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

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

.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.api-docs {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
}

.api-docs pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 16px;
    border-radius: var(--border-radius-sm);
    overflow-x: auto;
    margin-top: 12px;
}

.api-docs code {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--accent-secondary);
}

/* ==================== Config Section ==================== */
.config-section {
    display: grid;
    gap: 24px;
}

.config-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group small {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.input-with-status {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-status input {
    flex: 1;
    padding-right: 40px;
}

.status-indicator {
    position: absolute;
    right: 14px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.status-indicator.configured {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-indicator.not-configured {
    background: var(--warning);
    box-shadow: 0 0 8px var(--warning);
}

.info-card ul {
    list-style: none;
}

.info-list li {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.info-list li:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-secondary);
}

.info-value {
    font-weight: 500;
}

/* ==================== Modal ==================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    width: 90%;
    max-width: 450px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

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

.modal-header h3 {
    margin-bottom: 0;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    transition: color var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

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

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    max-width: 400px;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--error);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast.info {
    border-left: 4px solid var(--info);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ==================== Utilities ==================== */
.hidden {
    display: none !important;
}

.loading {
    pointer-events: none;
    opacity: 0.7;
}

.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    .app-container {
        padding: 16px;
    }

    .nav-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tab {
        padding: 10px 16px;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    .nav-tab span {
        display: none;
    }

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

    .card {
        padding: 20px;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .token-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .token-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .modal-content {
        margin: 16px;
        padding: 20px;
    }
}

@media (min-width: 768px) {
    .header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .config-section {
        grid-template-columns: 2fr 1fr;
    }
}

/* ==================== Login Screen ==================== */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 40px;
    backdrop-filter: blur(10px);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header svg {
    color: var(--accent-primary);
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.login-form input[type="text"],
.login-form input[type="password"] {
    width: 100%;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all var(--transition-normal);
}

.login-form input[type="text"]:focus,
.login-form input[type="password"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.login-form input::placeholder {
    color: var(--text-muted);
}

.login-error {
    padding: 12px 16px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--border-radius-sm);
    color: var(--error);
    font-size: 0.9rem;
    text-align: center;
}

.btn-block {
    width: 100%;
}

/* ==================== Logout Button ==================== */
.btn-logout {
    padding: 10px 16px;
    font-size: 0.85rem;
}

.header {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

@media (min-width: 768px) {
    .header {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .header .nav-tabs {
        flex: 1;
        justify-content: center;
    }
}

/* ==================== Database Section ==================== */
.database-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.db-controls {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.search-box {
    flex: 1;
    min-width: 250px;
    position: relative;
    display: flex;
    align-items: center;
}

.search-box svg {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: all var(--transition-normal);
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.per-page-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.per-page-control label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.per-page-control select {
    padding: 10px 32px 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a0a0b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.per-page-control select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Data Table */
.table-container {
    overflow-x: auto;
    margin-bottom: 20px;
}

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

.data-table th,
.data-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

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

.data-table .actions {
    display: flex;
    gap: 8px;
}

.data-table .btn-icon {
    padding: 6px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.data-table .btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.data-table .btn-icon.delete:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--error);
    color: var(--error);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.pagination-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-indicator {
    color: var(--text-secondary);
    font-size: 0.9rem;
    min-width: 120px;
    text-align: center;
}

/* Modal Large */
.modal-lg {
    max-width: 550px;
}

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

@media (max-width: 500px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* Loading state for table */
.data-table.loading tbody {
    opacity: 0.5;
    pointer-events: none;
}