:root {
    --primary: #0066cc;
    --primary-dark: #0052a3;
    --success: #0d7a3d;
    --danger: #cc0000;
    --warning: #ff9900;
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --border: #e0e0e0;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* ===========================
   Auth Screen
   =========================== */

#authScreen {
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0066cc 0%, #0052a3 100%);
    padding: 20px;
}

/* #authScreen.active (specificity 101) must beat .screen.active's
   "display: block" (specificity 20) to restore flex centering, and the
   plain #authScreen rule above must NOT set display at all -- an
   unconditional "display: flex" there would override .screen's
   "display: none" (specificity 10) even without the "active" class,
   which is exactly the bug this fixes: the login screen stayed visible
   (flex-displayed) after logging in, no matter what class JS toggled. */
#authScreen.active {
    display: flex;
}

.auth-container {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: 40px;
}

.lang-switch {
    display: flex;
    gap: 6px;
}

.auth-header .lang-switch {
    justify-content: center;
    margin-bottom: 16px;
}

.lang-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lang-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.lang-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h1 {
    font-size: 32px;
    margin-bottom: 8px;
    color: #0066cc;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border);
}

.auth-tab-btn {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.auth-tab-btn.active {
    color: #0066cc;
    border-bottom-color: #0066cc;
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.auth-form h2 {
    margin-bottom: 20px;
    font-size: 20px;
}

/* ===========================
   Main Application
   =========================== */

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border);
}

.header-content h1 {
    font-size: 28px;
    margin-bottom: 4px;
    color: #0066cc;
}

.header-content .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 15px;
}

#userEmail {
    font-weight: 500;
}

.role-badge {
    background: #f0f0f0;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    color: #0066cc;
}

/* ===========================
   Tabs Navigation
   =========================== */

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
}

.tab-btn {
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    white-space: nowrap;
}

.tab-btn.active {
    color: #0066cc;
    border-bottom-color: #0066cc;
}

.tab-btn:hover {
    color: #0066cc;
}

.tab-content {
    display: none;
}

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

.unlock-mode-btn {
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    white-space: nowrap;
}

.unlock-mode-btn.active {
    color: #0066cc;
    border-bottom-color: #0066cc;
}

.unlock-mode-btn:hover {
    color: #0066cc;
}

/* ===========================
   Form Elements
   =========================== */

.form-group {
    margin-bottom: 20px;
}

.password-requirements {
    list-style: none;
    margin-top: 8px;
    display: grid;
    gap: 4px;
}

.password-requirements li {
    font-size: 12px;
    color: var(--text-secondary);
    padding-left: 20px;
    position: relative;
}

.password-requirements li::before {
    content: "✗";
    position: absolute;
    left: 0;
    color: var(--danger);
    font-weight: 700;
}

.password-requirements li.met {
    color: var(--success);
}

.password-requirements li.met::before {
    content: "✓";
    color: var(--success);
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.3s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

textarea {
    resize: vertical;
    font-family: 'Monaco', 'Courier', monospace;
}

/* ===========================
   Buttons
   =========================== */

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

.btn-primary {
    background: #0066cc;
    color: white;
    width: 100%;
    margin-top: 20px;
}

.btn-primary:hover {
    background: #0052a3;
}

.btn-secondary {
    background: #f0f0f0;
    color: #0066cc;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-danger {
    background: #cc0000;
    color: white;
}

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

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* ===========================
   Cards & Containers
   =========================== */

.card {
    background: white;
    border-radius: 8px;
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card h2 {
    margin-bottom: 24px;
    font-size: 22px;
    color: var(--text-primary);
}

.info-box {
    background: #f0f7ff;
    border-left: 4px solid #0066cc;
    padding: 16px;
    border-radius: 6px;
    margin: 20px 0;
    font-size: 14px;
}

.info-box strong {
    color: #0066cc;
}

.info-box ul {
    margin-left: 20px;
    margin-top: 8px;
}

.info-box li {
    margin: 6px 0;
}

/* ===========================
   Status Messages
   =========================== */

.status-message {
    padding: 12px 16px;
    border-radius: 6px;
    margin-top: 10px;
    display: none;
    font-size: 14px;
}

.status-message.show {
    display: block;
}

.status-message.success {
    background: #e6f5e6;
    color: #0d7a3d;
    border: 1px solid #0d7a3d;
}

.status-message.error {
    background: #ffe6e6;
    color: #cc0000;
    border: 1px solid #cc0000;
}

/* ===========================
   Vault Items
   =========================== */

.vaults-list {
    display: grid;
    gap: 16px;
}

.vault-item {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.vault-item h3 {
    margin-bottom: 8px;
    color: #0066cc;
}

.vault-id {
    font-family: 'Monaco', 'Courier', monospace;
    font-size: 12px;
    color: var(--text-secondary);
    word-break: break-all;
    margin: 8px 0;
}

.vault-date {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 8px 0;
}

.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    margin: 8px 0;
}

.status-badge.pending {
    background: #fff3cd;
    color: #856404;
}

.status-badge.approved {
    background: #d4edda;
    color: #155724;
}

.status-badge.rejected {
    background: #f8d7da;
    color: #721c24;
}

.vault-item .btn {
    margin-right: 8px;
    margin-top: 8px;
    display: inline-block;
    width: auto;
}

/* ===========================
   Modal
   =========================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 40px;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    margin-bottom: 20px;
    text-align: center;
    color: #0066cc;
}

.success-box {
    background: #d4edda;
    border: 1px solid #0d7a3d;
    color: #155724;
    padding: 16px;
    border-radius: 6px;
    margin-bottom: 20px;
    text-align: center;
}

/* ===========================
   Keys Grid
   =========================== */

.keys-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin: 24px 0;
}

.key-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.key-number {
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 700;
    margin-bottom: 12px;
    display: inline-block;
}

.key-holder {
    font-weight: 600;
    color: #0066cc;
    margin-bottom: 4px;
}

.key-role {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.key-hex {
    background: white;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 6px;
    font-family: 'Monaco', 'Courier', monospace;
    font-size: 11px;
    word-break: break-all;
    color: var(--text-secondary);
    margin-bottom: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.key-card .btn {
    width: 100%;
    margin-top: 8px;
}

/* ===========================
   Emergency Contacts
   =========================== */

.holders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.holder-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: 8px;
}

.holder-card label {
    font-size: 13px;
    font-weight: 600;
    color: #0066cc;
}

.holder-card input {
    margin-top: 8px;
    margin-bottom: 8px;
}

.holder-note {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
}

.contacts-list {
    display: grid;
    gap: 12px;
}

.contact-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.contact-info h4 {
    color: #0066cc;
    margin-bottom: 4px;
}

.contact-info p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 2px 0;
}

/* ===========================
   Approvals List
   =========================== */

.approvals-list {
    display: grid;
    gap: 16px;
}

.approval-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.approval-info h3 {
    color: #0066cc;
    margin-bottom: 8px;
}

.approval-info p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 4px 0;
}

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

/* ===========================
   Secret Box
   =========================== */

.secret-box {
    background: #f0f7ff;
    border: 2px solid #0066cc;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
}

.secret-box h3 {
    color: #0066cc;
    margin-bottom: 12px;
}

.secret-content {
    background: white;
    border: 1px solid #0066cc;
    padding: 16px;
    border-radius: 6px;
    margin-bottom: 16px;
}

.secret-text {
    font-family: 'Monaco', 'Courier', monospace;
    font-size: 13px;
    color: var(--text-primary);
    word-break: break-all;
    white-space: pre-wrap;
}

.secret-box .btn {
    width: 100%;
}

/* ===========================
   Section Titles
   =========================== */

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin: 24px 0 16px;
    color: var(--text-primary);
}

.instructions {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 8px;
    margin: 24px 0;
}

.instructions h3 {
    margin-bottom: 12px;
    color: #0066cc;
}

.instructions ol {
    margin-left: 20px;
}

.instructions li {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

/* ===========================
   Responsive
   =========================== */

@media (max-width: 768px) {
    .header-content h1 {
        font-size: 24px;
    }
    
    .keys-grid {
        grid-template-columns: 1fr;
    }
    
    .holders-grid {
        grid-template-columns: 1fr;
    }
    
    .approval-item,
    .contact-item {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .approval-actions {
        width: 100%;
        margin-top: 12px;
    }
    
    .approval-actions .btn {
        flex: 1;
    }
    
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 12px;
    }
    
    .card {
        padding: 16px;
    }
    
    .auth-container {
        padding: 24px;
    }
    
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .user-menu {
        width: 100%;
        justify-content: flex-end;
    }
}
