:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7fa;
    --bg-card: #ffffff;
    --bg-input: #f0f0f5;
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --accent: #6c5ce7;
    --accent-hover: #5a4bd1;
    --accent-glow: rgba(108, 92, 231, 0.12);
    --accent-light: rgba(108, 92, 231, 0.06);
    --danger: #e74c3c;
    --success: #2ecc71;
    --warning: #f39c12;
    --border: #e2e2ea;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ===== LOGIN PAGE ===== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-secondary);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
}

.login-card .login-logo {
    display: block;
    height: 140px;
    margin: 0 auto 1.5rem;
    filter: brightness(0.2);
}

.login-card .subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus, .form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn {
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

.btn-small { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

.error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    display: none;
}

.toggle-link {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.toggle-link a {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
}

/* ===== 2FA SETUP ===== */
.qr-container {
    text-align: center;
    padding: 1rem 0;
}

.qr-container img {
    max-width: 200px;
    border-radius: 8px;
    margin: 1rem 0;
}

.secret-key {
    font-family: monospace;
    font-size: 0.8rem;
    background: var(--bg-input);
    padding: 0.5rem;
    border-radius: 6px;
    word-break: break-all;
    margin: 0.5rem 0;
}

/* ===== MAIN APP ===== */
.app-container {
    display: none;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    position: sticky;
    top: 0;
    z-index: 50;
}

.app-header .header-logo {
    height: 60px;
    filter: brightness(0.15);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

/* ===== WORKSPACE ===== */
.workspace {
    flex: 1;
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    width: 100%;
}

.step-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.step-card.hidden { display: none; }

.step-header {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.step-number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-number.done {
    background: var(--success);
}

.step-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.text-area-large {
    width: 100%;
    min-height: 150px;
    padding: 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
    line-height: 1.6;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.text-area-large:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.scan-buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ===== ENTITY LIST ===== */
.entity-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
}

.entity-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg-input);
    border-radius: 8px;
    font-size: 0.9rem;
}

.entity-item .entity-text {
    flex: 1;
    font-family: monospace;
    font-weight: 500;
}

.entity-item .entity-type {
    font-size: 0.72rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 600;
    text-transform: uppercase;
}

.entity-item .entity-source {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.entity-toggle {
    appearance: none;
    width: 40px;
    height: 22px;
    background: #ccc;
    border-radius: 11px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.entity-toggle:checked { background: var(--success); }

.entity-toggle::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.entity-toggle:checked::after { transform: translateX(18px); }

.no-entities {
    color: var(--text-secondary);
    text-align: center;
    padding: 1rem;
    font-size: 0.9rem;
}

/* ===== MASKED PREVIEW ===== */
.masked-preview {
    background: var(--bg-input);
    padding: 1rem;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre-wrap;
    margin: 1rem 0;
    border: 1px solid var(--border);
}

.validate-btn {
    width: 100%;
    padding: 0.8rem;
    background: var(--success);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.validate-btn:hover { background: #27ae60; }
.validate-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== CLOUD SEND ===== */
.provider-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.provider-row select, .provider-row input {
    flex: 1;
    padding: 0.5rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
}

.provider-row select:focus, .provider-row input:focus {
    border-color: var(--accent);
}

.send-buttons {
    display: flex;
    gap: 0.5rem;
}

.send-buttons .btn {
    flex: 1;
    padding: 0.8rem;
    font-size: 0.95rem;
}

/* ===== RESPONSE ===== */
.response-content {
    background: var(--bg-input);
    padding: 1.2rem;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 1rem 0;
    min-height: 60px;
    border: 1px solid var(--border);
}

.response-model {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.response-actions {
    display: flex;
    gap: 0.5rem;
}

/* ===== SETTINGS MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal h2 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.settings-section {
    margin-bottom: 1.5rem;
}

.settings-section h3 {
    font-size: 0.95rem;
    margin-bottom: 0.8rem;
    color: var(--text-secondary);
}

/* ===== LOADING SPINNER ===== */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 0.5rem;
}

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

/* ===== RESET LINK ===== */
.reset-link {
    text-align: center;
    margin-top: 0.5rem;
}

.reset-link a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 500;
}

.reset-link a:hover { text-decoration: underline; }

/* ===== 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-secondary); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .app-header { padding: 0.6rem 1rem; }
    .workspace { padding: 1rem; }
    .step-card { padding: 1.2rem; }
    .modal { width: 95%; padding: 1.5rem; }
    .send-buttons { flex-direction: column; }
}
