/* ============================================
   CryptVault PWA — Dark Theme (iPhone Optimized)
   ============================================ */

/* ─── Reset & Base ────────────────────────────── */

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

:root {
    --bg: #0a0a0f;
    --bg-card: #141420;
    --bg-input: #1a1a2e;
    --bg-hover: #1e1e32;
    --border: #2a2a3e;
    --text: #e8e8f0;
    --text-muted: #8888a0;
    --text-dim: #5a5a70;
    --primary: #6366f1;
    --primary-hover: #5558e8;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html,
body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;
}

body {
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

#app {
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* ─── Screen Layout ───────────────────────────── */

.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 16px 16px;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}

.login-screen {
    justify-content: flex-start;
    align-items: center;
    padding: 24px;
    padding-top: 60px;
}

/* ─── Navigation ──────────────────────────────── */

.pwa-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
}

.pwa-nav-title {
    font-weight: 600;
    font-size: 17px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}

.pwa-nav-actions {
    display: flex;
    gap: 4px;
}

.pwa-nav-spacer {
    width: 36px;
}

.btn-close {
    font-size: 18px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* ─── Login ───────────────────────────────────── */

.login-card {
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 15px;
}

.login-divider {
    display: flex;
    align-items: center;
    margin: 16px 0;
    color: var(--text-dim);
    font-size: 13px;
}

.login-divider::before,
.login-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border);
}

.login-divider span {
    padding: 0 12px;
}

.login-btn-unlock {
    margin-top: 0;
}

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

.login-btn-reregister {
    margin-top: 16px;
    font-size: 13px;
}

.login-btn-cancel {
    margin-top: 4px;
}

.login-btn-skip {
    margin-top: 8px;
}

.text-danger {
    color: var(--danger);
}

.loading {
    color: var(--text-muted);
    font-size: 15px;
}

/* ─── Buttons ─────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: var(--font);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    opacity: 0.85;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text);
}

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

.btn-danger:hover {
    background: var(--danger-hover);
}

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

.btn-full {
    width: 100%;
}

/* ─── Forms ───────────────────────────────────── */

.form-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    /* Prevents iOS zoom */
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus {
    border-color: var(--primary);
}

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

.form-input-sm {
    width: auto;
    padding: 6px 10px;
    font-size: 14px;
}

/* ─── Selects (Dropdowns) ────────────────────── */

select.form-input,
select.form-input-sm,
.gen-controls select,
.settings-list select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238888a0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    cursor: pointer;
}

select.form-input:focus,
.gen-controls select:focus {
    border-color: var(--primary);
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

/* ─── Search ──────────────────────────────────── */

.vault-header {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: stretch;
}

.vault-header .search-input {
    flex: 1;
}

.vault-header .btn {
    white-space: nowrap;
    padding: 10px 20px;
}

.search-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    outline: none;
}

.search-input:focus {
    border-color: var(--primary);
}

.search-input::placeholder {
    color: var(--text-dim);
}

.entry-count {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 12px;
}

/* ─── Pull-to-Refresh ────────────────────────── */

.pull-indicator {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    height: 0;
    overflow: hidden;
    transition: height 0.2s, opacity 0.2s;
    opacity: 0;
}

.pull-indicator.visible {
    height: 36px;
    line-height: 36px;
    opacity: 1;
}

.pull-indicator.syncing {
    color: var(--primary);
}

/* ─── Entry List ──────────────────────────────── */

.entries-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.entry-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.entry-row:active {
    background: var(--bg-hover);
}

.entry-info {
    flex: 1;
    min-width: 0;
}

.entry-app {
    font-weight: 500;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entry-user {
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.copy-btn {
    flex-shrink: 0;
    margin-left: 8px;
}

.empty-state {
    text-align: center;
    color: var(--text-dim);
    padding: 40px 0;
    font-size: 15px;
}

/* ─── Entry Detail ────────────────────────────── */

.detail-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
}

.detail-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-row label {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.detail-value {
    font-size: 15px;
    word-break: break-all;
}

.detail-value.password-hidden {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.detail-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.detail-meta {
    display: flex;
    justify-content: space-between;
    color: var(--text-dim);
    font-size: 12px;
}

/* ─── Entry Form ──────────────────────────────── */

.entry-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.password-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.password-input-row .form-input {
    flex: 1;
}

/* ─── Generator ───────────────────────────────── */

.gen-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
}

.gen-panel {
    display: none;
}

.gen-panel.active {
    display: block;
}

.gen-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.gen-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.gen-tab.active {
    background: var(--primary);
    color: white;
}

.gen-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.gen-controls label {
    color: var(--text-muted);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.gen-controls select,
.gen-sep-input,
.gen-len-input {
    width: auto;
    padding: 6px 10px;
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
}

.gen-controls select {
    padding-right: 30px;
}

.gen-sep-input {
    width: 48px;
    text-align: center;
}

.gen-len-input {
    width: 64px;
}

.gen-output {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-size: 15px;
    word-break: break-all;
    line-height: 1.6;
    margin-bottom: 8px;
}

.gen-output.mono {
    font-family: var(--mono);
    font-size: 14px;
}

.gen-entropy {
    color: var(--success);
    font-size: 13px;
    margin-bottom: 12px;
}

.gen-entropy.strength-extreme {
    color: var(--success);
}

.gen-entropy.strength-strong {
    color: var(--success);
}

.gen-entropy.strength-moderate {
    color: var(--warning);
}

.gen-entropy.strength-weak {
    color: var(--danger);
}

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

/* ─── Settings ────────────────────────────────── */

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 15px;
}

.settings-danger {
    margin-top: 24px;
}

.text-muted {
    color: var(--text-muted);
}

/* ─── Toast ───────────────────────────────────── */

.toast-container {
    position: fixed;
    top: calc(var(--safe-top) + 16px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    pointer-events: auto;
    transition: opacity 0.3s;
    max-width: 320px;
}

.toast-success {
    background: var(--success);
    color: white;
}

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

.toast-warning {
    background: var(--warning);
    color: #1a1a2e;
}

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

/* ─── Responsive ──────────────────────────────── */

@media (min-width: 480px) {
    .screen {
        padding: 0 24px 24px;
    }
}

/* iOS safe area handling */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
}