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

:root {
    --bg: #1C1C24;
    --surface: #262630;
    --sidebar-bg: #212128;
    --text: #D9D9E0;
    --text-muted: #808088;
    --primary: #6495ED;
    --accent: #FF8C00;
    --success: #4CD94C;
    --error: #E64D4D;
    --selected-bg: #3F5A8C;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#app { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 40px 20px; }

.page { display: none; width: 100%; max-width: 600px; }
.page.active { display: block; }
#page-main.active { display: block; max-width: 1000px; }

/* Auth card */
.auth-card {
    background: var(--surface);
    padding: 48px 40px;
    border-radius: var(--radius);
    text-align: center;
    max-width: 420px;
    margin: 0 auto;
}
.brand { color: var(--primary); font-size: 36px; margin-bottom: 4px; }
.brand-small { color: var(--primary); font-size: 20px; }
.subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 32px; }

input[type="email"], input[type="password"], input[type="text"], input[type="number"], input[type="url"], input[type="date"], select, textarea {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: var(--bg);
    border: 1px solid #3a3a4a;
    border-radius: 6px;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
select { appearance: none; cursor: pointer; }

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-top: 8px;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-outline {
    padding: 6px 16px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--text-muted);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}
.btn-outline:hover { border-color: var(--text); color: var(--text); }

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 14px;
    cursor: pointer;
}
.btn-text:hover { text-decoration: underline; }

.btn-copy {
    padding: 4px 10px;
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 8px;
    white-space: nowrap;
}
.btn-copy:hover { background: var(--primary); color: white; }

.toggle-auth { color: var(--text-muted); font-size: 13px; margin-top: 16px; }
.toggle-auth a { color: var(--primary); text-decoration: none; }
.toggle-auth a:hover { text-decoration: underline; }

.status-message { font-size: 13px; margin-top: 12px; min-height: 20px; }
.status-message.error { color: var(--error); }
.status-message.success { color: var(--success); }

.muted { color: var(--text-muted); font-size: 14px; margin-top: 16px; }

/* Main container (share view) */
.main-container { width: 100%; }
.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #3a3a4a;
}

/* Inbox items */
.inbox-item {
    background: var(--surface);
    padding: 16px 20px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.inbox-item:hover { background: var(--selected-bg); }
.inbox-item .from { color: var(--text-muted); font-size: 13px; }
.inbox-item .share-label { font-size: 15px; }

/* Card display (share view) */
.card-display {
    background: var(--surface);
    padding: 24px;
    border-radius: var(--radius);
    margin-top: 16px;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #3a3a4a;
}
.card-name { font-size: 22px; font-weight: 600; }
.card-type-badge {
    background: var(--accent);
    color: white;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}
.card-field {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #2a2a3a;
}
.card-field:last-child { border-bottom: none; }
.card-field .label { color: var(--text-muted); font-size: 13px; width: 140px; flex-shrink: 0; }
.card-field .value { font-size: 15px; flex: 1; }
.mono { font-family: 'SF Mono', 'Menlo', 'Monaco', monospace; letter-spacing: 1px; }

#totp-input {
    max-width: 200px;
    text-align: center;
    font-size: 24px;
    font-family: 'SF Mono', 'Menlo', monospace;
    letter-spacing: 8px;
    margin: 16px auto;
    display: block;
}

#btn-decrypt { max-width: 200px; margin: 0 auto; display: block; }

/* ── App Layout ── */

.app-layout {
    display: flex;
    width: 100%;
    max-width: 1000px;
    height: calc(100vh - 100px);
}

.sidebar {
    width: 200px;
    background: var(--sidebar-bg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius) 0 0 var(--radius);
    flex-shrink: 0;
}

.sidebar nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 20px;
}

.nav-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    width: 100%;
}
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--selected-bg); color: var(--primary); }
.count { color: var(--text-muted); font-size: 12px; }

.main-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--bg);
    border-radius: 0 var(--radius) var(--radius) 0;
}

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

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

#search-input {
    width: 200px;
    padding: 8px 12px;
    font-size: 13px;
    margin-bottom: 0;
}

.btn-primary-small {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}
.btn-primary-small:hover { opacity: 0.9; }

.category-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}
.tab {
    padding: 6px 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    border-radius: 4px;
}
.tab:hover { background: var(--surface); }
.tab.active { background: var(--primary); color: white; }

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

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}
.list-item:hover { background: var(--selected-bg); }
.list-item .item-info { flex: 1; }
.list-item .item-name { font-size: 15px; }
.list-item .item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.list-item .item-meta { text-align: right; }
.list-item .item-type { font-size: 12px; color: var(--accent); }
.list-item .item-last4 { font-size: 13px; color: var(--text-muted); font-family: 'SF Mono', 'Menlo', monospace; }
.list-item .online-icon { color: var(--primary); font-size: 10px; margin-left: 4px; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ── Modal ── */

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}
.modal-content {
    background: var(--bg);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #3a3a4a;
}
.modal-header h3 { flex: 1; text-align: center; }
.modal-actions { display: flex; gap: 8px; }

/* ── Form styles ── */

.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 4px;
}
.form-group input, .form-group textarea, .form-group select {
    margin-bottom: 0;
}
.form-group textarea {
    min-height: 60px;
    resize: vertical;
}
.form-row {
    display: flex;
    gap: 12px;
}
.form-row .form-group { flex: 1; }

.form-section-label {
    font-size: 13px;
    color: var(--text-muted);
    margin: 20px 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid #2a2a3a;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.selector-group {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}
.selector-btn {
    padding: 6px 14px;
    background: var(--surface);
    border: 1px solid #3a3a4a;
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}
.selector-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.btn-danger {
    padding: 8px 16px;
    background: var(--error);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}
.btn-danger:hover { opacity: 0.9; }

.btn-secondary {
    padding: 8px 16px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid #3a3a4a;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}
.btn-secondary:hover { background: var(--selected-bg); }

.btn-save {
    padding: 10px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 8px;
}
.btn-save:hover { opacity: 0.9; }

/* ── Detail view ── */

.detail-field {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #2a2a3a;
}
.detail-field:last-child { border-bottom: none; }
.detail-field .label { color: var(--text-muted); font-size: 13px; width: 140px; flex-shrink: 0; }
.detail-field .value { font-size: 15px; flex: 1; word-break: break-all; }
.detail-field .field-actions { display: flex; gap: 4px; margin-left: 8px; flex-shrink: 0; }

.btn-toggle-mask {
    padding: 4px 8px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid #3a3a4a;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}
.btn-toggle-mask:hover { border-color: var(--text); color: var(--text); }

.detail-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #3a3a4a;
}
.detail-actions .btn-primary-small { flex: 1; text-align: center; }
.detail-actions .btn-danger { flex: 1; text-align: center; }

/* Custom fields */
.custom-field-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-bottom: 8px;
}
.custom-field-row input { flex: 1; margin-bottom: 0; }
.custom-field-row .btn-remove-field {
    padding: 10px 12px;
    background: transparent;
    color: var(--error);
    border: 1px solid var(--error);
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
}

/* ── Footer ── */
.footer {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 12px;
}
.footer a { color: var(--primary); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ── Mobile ── */
@media (max-width: 768px) {
    .app-layout { flex-direction: column; height: auto; min-height: calc(100vh - 100px); }
    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        border-radius: var(--radius) var(--radius) 0 0;
        gap: 8px;
        align-items: center;
    }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; margin-top: 0; gap: 4px; }
    .sidebar .brand-small { margin-right: auto; }
    .nav-item { width: auto; }
    #search-input { width: 120px; }
    .form-row { flex-direction: column; }
    .main-content { border-radius: 0 0 var(--radius) var(--radius); }
    .content-header { flex-wrap: wrap; gap: 8px; }
    .detail-field { flex-wrap: wrap; }
    .detail-field .label { width: 100%; margin-bottom: 4px; }
}

@media (max-width: 480px) {
    .auth-card { padding: 32px 24px; }
    .card-field { flex-wrap: wrap; }
    .card-field .label { width: 100%; margin-bottom: 4px; }
}
