@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --color-bg: #F2EDE4;
    --color-surface: #FFFFFF;
    --color-text-primary: #1A1A18;
    --color-text-muted: #5F5E5A;
    --color-accent: #C0392B;
    --color-border: #E8E0D6;
    --color-code-bg: #1A1A18;
    --color-code-syntax: #4A9CE8;
    --font-display: Georgia, 'Times New Roman', serif;
    --font-ui: 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
    --shadow-sm: 0 1px 3px rgba(26, 26, 24, 0.08);
    --shadow: 0 2px 8px rgba(26, 26, 24, 0.12);
    --shadow-lg: 0 8px 24px rgba(26, 26, 24, 0.16);
}

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

/* Font size support */
body {
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.5;
    background: var(--color-bg);
    color: var(--color-text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.font-small {
    font-size: 14px;
}

body.font-medium {
    font-size: 16px;
}

body.font-large {
    font-size: 18px;
}

/* Screens */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: block;
}

/* Auth Screen */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    font-family: var(--font-display);
    font-size: 1.75rem;
    color: var(--color-text-primary);
    margin-bottom: 0.5rem;
}

.auth-header p {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.auth-form {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 2rem 1.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border);
}

.auth-form .form-group {
    margin-bottom: 1.25rem;
}

.auth-form .btn {
    width: 100%;
    margin-top: 0.5rem;
}

/* App Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.header-content h1 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
}

.header-content .header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Tabs */
.tabs {
    display: flex;
    max-width: 600px;
    margin: 0 auto;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.tab {
    flex: 1;
    padding: 0.75rem 1rem;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    min-height: 44px;
}

.tab.active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
}

.tab:hover {
    color: var(--color-text-primary);
}

/* App Content */
.app-content {
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 5rem;
}

/* Search Bar */
.search-bar {
    width: 100%;
    padding: 0.75rem 1rem;
    padding-left: 2.5rem;
    font-size: 0.9rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text-primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 44px;
}

.search-bar:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
}

.search-wrapper {
    position: relative;
    margin-bottom: 1rem;
}

.search-wrapper::before {
    content: '';
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%235F5E5A'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}

/* Item List */
.item-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Item Card */
.item-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
}

.item-card:hover {
    box-shadow: var(--shadow);
}

.item-card-header {
    padding: 0.875rem 1rem 0.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.item-card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 0.5rem;
}

.item-card-body {
    padding: 0.25rem 1rem 0.75rem;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.item-card-body p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-card-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--color-border);
    background: rgba(242, 237, 228, 0.3);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(26, 26, 24, 0.5);
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--color-surface);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 700;
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%) translateY(-120%);
    background: var(--color-surface);
    color: var(--color-text-primary);
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 2000;
    transition: transform 0.3s ease;
    max-width: calc(100% - 2rem);
    text-align: center;
    border-left: 4px solid var(--color-accent);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    border-left-color: #27ae60;
}

.toast.error {
    border-left-color: var(--color-accent);
}

/* Form Elements */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.375rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-family: var(--font-ui);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text-primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 44px;
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.6;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: var(--font-ui);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    min-height: 44px;
    min-width: 44px;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--color-accent);
    color: #fff;
}

.btn-primary:hover {
    background: #a93226;
    box-shadow: var(--shadow-sm);
}

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

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

.btn-danger {
    background: #e74c3c;
    color: #fff;
}

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

.btn-icon {
    background: none;
    border: none;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    color: var(--color-text-muted);
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

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

/* Password Field */
.password-field {
    position: relative;
    display: flex;
    align-items: center;
}

.password-field input {
    flex: 1;
    padding-right: 3rem;
    font-family: var(--font-mono);
}

.password-field .toggle-visibility {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--color-text-muted);
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.password-field .toggle-visibility:hover {
    color: var(--color-text-primary);
    background: var(--color-bg);
}

/* TOTP Display */
.totp-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--color-code-bg);
    border-radius: 8px;
    font-family: var(--font-mono);
}

.totp-display .totp-code {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-code-syntax);
    letter-spacing: 0.2em;
}

.totp-display .totp-countdown {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    margin-left: auto;
}

/* Settings Panel */
.settings-panel {
    max-height: 0;
    overflow: hidden;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    transition: max-height 0.3s ease;
}

.settings-panel.open {
    max-height: 300px;
}

.settings-panel-content {
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.settings-panel-content label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.5rem;
    display: block;
}

.settings-panel-content .font-size-options {
    display: flex;
    gap: 0.5rem;
}

.settings-panel-content .font-size-options button {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
    cursor: pointer;
    font-size: 0.85rem;
    min-height: 44px;
    transition: border-color 0.2s, background 0.2s;
}

.settings-panel-content .font-size-options button.active {
    border-color: var(--color-accent);
    background: rgba(192, 57, 43, 0.05);
    color: var(--color-accent);
    font-weight: 600;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--color-text-muted);
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state h3 {
    font-family: var(--font-display);
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
    color: var(--color-text-primary);
}

.empty-state p {
    font-size: 0.875rem;
}

/* FAB (Floating Action Button) */
.fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    z-index: 50;
    transition: transform 0.2s, box-shadow 0.2s;
}

.fab:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 30px rgba(192, 57, 43, 0.3);
}

.fab:active {
    transform: scale(0.95);
}

/* Copy Button */
.copy-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    min-height: 32px;
    min-width: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.copy-btn.copied {
    background: #27ae60;
    color: #fff;
    border-color: #27ae60;
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-radius: 4px;
    background: var(--color-bg);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}

.badge.badge-accent {
    background: rgba(192, 57, 43, 0.08);
    color: var(--color-accent);
    border-color: rgba(192, 57, 43, 0.2);
}

/* Loading overlay */
.loading {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(242, 237, 228, 0.85);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

.loader {
    width: 40px;
    height: 40px;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Utility */
.hidden {
    display: none !important;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* Desktop adjustments */
@media (min-width: 640px) {
    .modal-content {
        border-radius: 16px;
        max-height: 80vh;
        margin: auto;
    }

    .modal {
        align-items: center;
        padding: 1rem;
    }

    .auth-form {
        padding: 2.5rem 2rem;
    }

    .app-content {
        padding: 1.5rem;
        padding-bottom: 5rem;
    }
}
