* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #0c0c14;
    color: #e0dce8;
    min-height: 100vh;
    line-height: 1.5;
}

.wrap {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Login page */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    overflow-x: hidden;
}

.login-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: radial-gradient(ellipse 120% 80% at 50% -20%, rgba(99, 102, 241, 0.12), transparent 50%),
                radial-gradient(ellipse 80% 50% at 80% 100%, rgba(79, 70, 229, 0.08), transparent 45%),
                #0c0c14;
}

.login-wrap {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: linear-gradient(165deg, rgba(26, 26, 46, 0.95) 0%, rgba(18, 18, 32, 0.98) 100%);
    border: 1px solid rgba(74, 69, 85, 0.6);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5),
                0 0 0 1px rgba(255, 255, 255, 0.03) inset;
    overflow: hidden;
}

.login-card-inner {
    padding: 2.5rem 2rem;
}

.login-brand {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-bottom: 0.5rem;
}

.login-logo {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #fff;
    background: linear-gradient(135deg, #e0dce8 0%, #a8a0b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-product {
    font-size: 0.9rem;
    font-weight: 500;
    color: #6366f1;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.login-tagline {
    margin: 0 0 1.75rem;
    font-size: 0.9rem;
    color: #78708a;
    line-height: 1.5;
}

.login-error {
    margin: 0 0 1.25rem;
    padding: 0.75rem 1rem;
    background: rgba(220, 38, 38, 0.12);
    border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: 10px;
    color: #fca5a5;
    font-size: 0.875rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.login-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #9088a0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.login-input {
    width: 100%;
    padding: 0.85rem 1rem;
    font-size: 1rem;
    background: rgba(15, 15, 24, 0.8);
    border: 1px solid rgba(58, 53, 85, 0.8);
    border-radius: 12px;
    color: #e0dce8;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-input::placeholder {
    color: #5a5575;
}

.login-input:hover {
    border-color: rgba(74, 69, 85, 1);
}

.login-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.login-btn {
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.9rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.login-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.login-btn:active {
    transform: translateY(0);
}

.login-btn-text {
    display: inline-block;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-logout {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    color: #9088a0;
    background: transparent;
    border: 1px solid #2a2a45;
    border-radius: 8px;
    text-decoration: none;
    transition: color 0.2s, border-color 0.2s;
}

.btn-logout:hover {
    color: #c08080;
    border-color: #4a4040;
}

header {
    margin-bottom: 2rem;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.75rem;
    font-weight: 600;
}

/* Database status indicator */
.db-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.85rem;
    background: #1a1a2e;
    border: 1px solid #2a2a45;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.db-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c08080;
    box-shadow: 0 0 6px rgba(192, 128, 128, 0.5);
    animation: pulse-disconnected 2s ease-in-out infinite;
}

.db-status[data-connected="1"] {
    border-color: #308050;
    background: rgba(48, 128, 80, 0.1);
}

.db-status[data-connected="1"] .db-indicator {
    background: #50c080;
    box-shadow: 0 0 8px rgba(80, 192, 128, 0.6);
    animation: pulse-connected 2s ease-in-out infinite;
}

.db-status[data-connected="1"] .db-text {
    color: #50c080;
}

.db-text {
    color: #c08080;
}

@keyframes pulse-connected {
    0%, 100% {
        box-shadow: 0 0 8px rgba(80, 192, 128, 0.6);
    }
    50% {
        box-shadow: 0 0 14px rgba(80, 192, 128, 0.9);
    }
}

@keyframes pulse-disconnected {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.subtitle {
    margin: 0;
    color: #9088a0;
    font-size: 0.95rem;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.alert-error {
    background: #3d2020;
    color: #e8a0a0;
    border: 1px solid #5c3030;
}

.cards {
    display: grid;
    gap: 1.25rem;
}

.card {
    background: #1a1a2e;
    border: 1px solid #2a2a45;
    border-radius: 14px;
    padding: 1.25rem 1.5rem;
    transition: background 0.15s, border-color 0.15s;
}

.card:hover {
    background: #1e1e32;
    border-color: #3a3555;
}

.card h2 {
    margin: 0 0 0.25rem;
    font-size: 1.15rem;
    font-weight: 600;
}

.card .meta {
    margin: 0 0 0.75rem;
    font-size: 0.8rem;
    color: #78708a;
}

.upload-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Wrapper: visible Browse button + hidden file input */
.browse-wrap {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.browse-wrap .file-input {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    z-index: -1;
}

/* Browse button (custom, always visible) */
.browse-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #e0dce8;
    background: linear-gradient(135deg, #2d2845 0%, #383355 100%);
    border: 1px solid #4a4565;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.browse-btn::before {
    content: '📁';
    font-size: 1rem;
    filter: grayscale(0.3);
}

.browse-btn:hover {
    background: linear-gradient(135deg, #383355 0%, #454065 100%);
    border-color: #5a5575;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.browse-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Show chosen file name next to Browse */
.browse-wrap .file-name {
    margin-left: 0.5rem;
    font-size: 0.85rem;
    color: #9088a0;
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Upload button – primary action */
.btn-upload {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    border: 1px solid #818cf8;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 3px 10px rgba(99, 102, 241, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.btn-upload::before {
    content: '↑';
    font-size: 1rem;
    font-weight: bold;
}

.btn-upload:hover {
    background: linear-gradient(135deg, #7c7ff2 0%, #5f57ea 100%);
    border-color: #9ca3ff;
    transform: translateY(-1px);
    box-shadow: 0 5px 16px rgba(99, 102, 241, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.btn-upload:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}

.btn-upload:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    background: linear-gradient(135deg, #2a2540 0%, #383355 100%);
    border-color: #3a3555;
    box-shadow: none;
}

/* Loading state for upload button */
.btn-upload.loading::after {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-save {
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #e0dce8;
    background: #3a3555;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-save:hover {
    background: #4a4565;
}

.btn-save:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.card .status {
    margin-left: 0.75rem;
    font-size: 0.85rem;
}

.card .status.ok {
    color: #80c080;
}

.card .status.err {
    color: #c08080;
}

/* Debug panel */
.debug-panel {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #2a2a45;
}

.debug-toggle {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    color: #9088a0;
    background: #1a1a2e;
    border: 1px solid #2a2a45;
    border-radius: 6px;
    cursor: pointer;
}

.debug-toggle:hover {
    color: #b0a8c0;
    border-color: #3a3555;
}

.debug-load-status {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    color: #9088a0;
}

.debug-load-status:empty {
    display: none;
}

#debug-load-status {
    padding: 0.4rem 0.6rem;
    background: #12121c;
    border-radius: 6px;
    border: 1px solid #2a2a45;
}

.debug-log-wrap {
    margin-top: 0.75rem;
    padding: 1rem;
    background: #0c0c14;
    border: 1px solid #2a2a45;
    border-radius: 8px;
}

.debug-log {
    margin: 0 0 0.75rem;
    padding: 0.75rem;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    color: #a0a0b0;
    background: #12121c;
    border-radius: 6px;
    max-height: 280px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.debug-clear {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
    color: #9088a0;
    background: transparent;
    border: 1px solid #2a2a45;
    border-radius: 6px;
    cursor: pointer;
}

.debug-clear:hover {
    color: #c08080;
    border-color: #4a4040;
}
