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

:root {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --surface2: #242424;
    --border: #333;
    --text: #e0e0e0;
    --text-dim: #888;
    --accent: #6c9bff;
    --accent-dim: #3a5a8a;
    --danger: #ff6b6b;
    --success: #6bff9b;
    --radius: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 50% 0%, #1a1a2e 0%, #0f0f0f 50%, #0a0a0a 100%);
    min-height: 100vh;
}

.login-container {
    text-align: center;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 340px;
}

.login-icon {
    color: var(--accent);
    margin-bottom: 1.2rem;
    opacity: 0.7;
}

.login-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
    color: var(--text);
    letter-spacing: -0.03em;
}

.login-subtitle {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 2rem;
    font-weight: 400;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.passcode-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-family: inherit;
    font-size: 1.3rem;
    padding: 0.85rem 1rem;
    text-align: center;
    letter-spacing: 0.25em;
    outline: none;
    width: 100%;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.passcode-input::placeholder {
    font-family: inherit;
    letter-spacing: 0.15em;
    opacity: 0.3;
    font-size: 1.1rem;
}

.passcode-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 155, 255, 0.1);
}

.error-msg {
    color: var(--danger);
    font-size: 0.82rem;
    min-height: 1.2em;
}

.btn-unlock {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.2rem;
    font-size: 0.95rem;
    border-radius: 12px;
}

/* Buttons */
.btn {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.85rem;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon:active {
    transform: scale(0.93);
    background: var(--surface2);
}

.btn-icon svg {
    display: block;
}

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

.btn-danger:active {
    background: rgba(255, 107, 107, 0.1);
}

/* Top bar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    padding: calc(var(--safe-top) + 0.5rem) 1rem 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: rgba(15, 15, 15, 0.85);
}

.mode-switch {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 0.45rem 1rem;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.mode-btn svg {
    opacity: 0.6;
}

.mode-btn.active {
    background: var(--accent);
    color: #000;
    font-weight: 600;
}

.mode-btn.active svg {
    opacity: 1;
}

.logout-btn {
    color: var(--text-dim);
    text-decoration: none;
    padding: 0.35rem;
    display: flex;
    align-items: center;
    opacity: 0.5;
    transition: opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.logout-btn:active {
    opacity: 1;
}

/* Tab bar */
.tab-bar {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem 0;
    align-items: center;
    transition: all 0.3s ease;
    overflow: hidden;
}

.tab-bar.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

.tab-group {
    display: flex;
    flex: 1;
    gap: 0;
}

.tab {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.5rem;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.tab svg {
    opacity: 0.5;
}

.tab:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}

.tab:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.tab.active {
    background: var(--accent-dim);
    border-color: var(--accent-dim);
    color: var(--text);
    font-weight: 600;
}

.tab.active svg {
    opacity: 1;
}

/* Add form */
.add-form {
    padding: 0.75rem 1rem;
    transition: all 0.3s ease;
    overflow: hidden;
}

.add-form.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

.add-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.add-input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.add-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 155, 255, 0.08);
}

.add-date {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.5rem;
    font-size: 0.85rem;
    outline: none;
    width: 2.5rem;
    min-width: 2.5rem;
    color-scheme: dark;
}

.add-date::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
}

.btn-add {
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: #000;
    font-size: 1.2rem;
    font-weight: 700;
    width: 2.5rem;
    height: 2.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.1s;
}

.btn-add:active {
    transform: scale(0.92);
}

/* Todo items */
.todo-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: opacity 0.2s;
}

.todo-item.done {
    opacity: 0.4;
}

.todo-item.done .todo-text {
    text-decoration: line-through;
}

.check-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.2rem;
    width: 1.8rem;
    height: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.check-btn.checked {
    color: var(--success);
}

.todo-text {
    flex: 1;
    font-size: 0.95rem;
    word-break: break-word;
}

.todo-date {
    color: var(--accent);
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.del-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.3rem;
    opacity: 0.5;
    -webkit-tap-highlight-color: transparent;
}

.del-btn:hover, .del-btn:active {
    color: var(--danger);
    opacity: 1;
}

.todo-check, .todo-del {
    display: flex;
    margin: 0;
}

/* Views */
.view {
    display: none;
}

.view.active {
    display: block;
}

/* Empty state */
.empty-state {
    text-align: center;
    color: var(--text-dim);
    padding: 4rem 1rem;
    font-size: 0.88rem;
    opacity: 0.5;
}

/* Notes */
.notes-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.note-select {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 0.5rem 0.7rem;
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    appearance: auto;
}

.notes-actions {
    display: flex;
    gap: 0.35rem;
}

.note-status {
    padding: 0 1rem;
    font-size: 0.75rem;
    color: var(--text-dim);
    height: 1rem;
    text-align: right;
}

.note-editor {
    display: block;
    width: 100%;
    min-height: calc(100vh - 10rem);
    background: var(--bg);
    border: none;
    color: var(--text);
    padding: 0 1rem 2rem;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.6;
    resize: none;
    outline: none;
}

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

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

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

/* PWA standalone adjustments */
@media (display-mode: standalone) {
    .topbar {
        padding-top: calc(var(--safe-top) + 0.5rem);
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .mode-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
}

/* Archive */
.archive-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.archive-title {
    font-size: 0.85rem;
    color: var(--text-dim);
    font-weight: 600;
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.btn-back:active {
    background: var(--surface2);
}

.btn-restore {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 0.3rem;
    display: flex;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}

.btn-restore:active {
    transform: scale(0.93);
}

.todo-action, .inline-form {
    display: flex;
    margin: 0;
}

.tab-archive {
    border-radius: 8px;
    flex: 0;
    padding: 0.45rem 0.5rem;
}

.tab-archive.active {
    background: var(--accent-dim);
    color: var(--text);
}

.archived-item {
    opacity: 0.7;
}

.archive-note-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.archive-note-title {
    flex: 1;
    font-size: 0.95rem;
}

.archive-note-actions {
    display: flex;
    gap: 0.25rem;
}
