:root {
    /* Light Theme */
    --bg-color: #f2f2f7;
    --card-bg: #ffffff;
    --text-color: #000000;
    --text-muted: #8e8e93;
    --primary-color: #007aff;
    --primary-hover: #005bb5;
    --border-color: #e5e5ea;
    --modal-bg: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] {
    /* Dark Theme */
    --bg-color: #000000;
    --card-bg: #1c1c1e;
    --text-color: #ffffff;
    --text-muted: #8e8e93;
    --primary-color: #0a84ff;
    --primary-hover: #0066cc;
    --border-color: #38383a;
    --modal-bg: rgba(28, 28, 30, 0.85);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

/* Better Inputs globally (removing native iOS styles) */
input, select, textarea, button {
    -webkit-appearance: none;
    appearance: none;
}

input:not([type="color"], [type="checkbox"]), select {
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    border-radius: 12px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
    transition: all 0.2s ease;
}

input:focus, select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
    outline: none;
}

/* Prevent iOS Zoom on focus */
input, select, textarea, [contenteditable] {
    font-size: 16px !important;
}

/* Views */
.view {
    display: none;
    min-height: 100vh;
    animation: fadeIn 0.4s ease forwards;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Login View */
.login-container {
    max-width: 400px;
    margin: 15vh auto;
    padding: 2rem;
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    text-align: center;
}

.logo-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.input-group {
    position: relative;
    margin-bottom: 1.5rem;
}

.input-group ion-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.2rem;
}

.input-group input {
    width: 100%;
    padding: 12px 15px 12px 45px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: transparent;
    color: var(--text-color);
    font-size: 1rem;
    transition: border-color 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s, transform 0.1s;
}

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

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    padding: 12px;
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
}

.error-text {
    color: #ff3b30;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* Home View */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: color 0.3s;
}

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

.logout-btn {
    color: #ff3b30;
}

.sort-select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.9rem;
}

.entries-container {
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 100px;
}

.entry-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 16px;
    margin-bottom: 1rem;
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.entry-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}

.entry-info h3 {
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

.entry-info p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.locked-icon {
    color: var(--text-muted);
    font-size: 1.2rem;
}

.fab-btn {
    position: fixed;
    bottom: 30px;
    left: 30px; /* As requested: "Sol altta yuvarlak bir + butonu" */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    border: none;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 122, 255, 0.4);
    transition: transform 0.2s, background 0.3s;
    z-index: 100;
}

.fab-btn:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

/* ===== EDITOR VIEW (iOS Notes Style) ===== */

/* Header */
.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.editor-header-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    font-family: inherit;
}

.editor-header-btn:active { opacity: 0.5; }

.editor-done-btn {
    background: var(--primary-color);
    color: #fff;
    border-radius: 18px;
    padding: 8px 20px;
}

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

.editor-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.editor-password {
    width: 120px;
    padding: 8px 12px;
    border-radius: 18px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 0.85rem;
    font-family: inherit;
}

.editor-password:focus {
    width: 160px;
    border-color: var(--primary-color);
    outline: none;
}

/* Body / Writing Area */
.editor-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 24px 20px 40px;
    min-height: 0;
}

.editor-date-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    margin-bottom: 16px;
    letter-spacing: 0.5px;
}

#editor {
    outline: none;
    line-height: 1.7;
    min-height: 300px;
    caret-color: var(--primary-color);
}

#editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    pointer-events: none;
    display: block;
    font-size: 1.1rem;
}

#editor > *:first-child {
    font-size: 1.6rem !important;
    font-weight: 700 !important;
    line-height: 1.3;
    margin-bottom: 8px;
}

/* ===== TOOLBAR ===== */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    overflow-x: auto;
    flex-shrink: 0;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.editor-toolbar::-webkit-scrollbar { display: none; }

.tb-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: var(--bg-color);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 1.15rem;
    transition: background 0.15s, color 0.15s;
}

.tb-btn:active { transform: scale(0.92); }
.tb-btn.active { background: var(--primary-color); color: #fff; }

.tb-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
    flex-shrink: 0;
}

.tb-color {
    width: 34px;
    height: 34px;
    padding: 0;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    background: transparent;
    flex-shrink: 0;
}

.tb-color::-webkit-color-swatch-wrapper { padding: 2px; }
.tb-color::-webkit-color-swatch { border: none; border-radius: 50%; }

.tb-select {
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    flex-shrink: 0;
}

/* ===== MODAL ===== */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active { display: flex; }

.modal-content {
    background: var(--modal-bg);
    padding: 2rem;
    border-radius: 16px;
    width: 90%;
    max-width: 350px;
    text-align: center;
}

.modal-content h3 { margin-bottom: 1rem; }

.modal-content input {
    width: 100%;
    padding: 12px;
    margin-bottom: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    font-family: inherit;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.modal-actions button { flex: 1; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .nav-left h2 { font-size: 1.3rem; }
    .top-nav { padding: 1.2rem 1rem; }
    .entries-container { padding: 1rem; }
    .entry-card { padding: 1.2rem; }
    .fab-btn { left: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); }

    body.editor-active {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
        touch-action: none;
    }

    #editor-view.active {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100vh; /* fallback before JS sets it */
        min-height: 0; /* override .view min-height:100vh */
        overflow: hidden;
    }

    .editor-header { padding: 10px 12px; }

    .editor-password {
        width: 90px;
        font-size: 0.8rem;
        padding: 7px 10px;
    }

    .editor-password:focus { width: 120px; }

    .editor-body {
        padding: 16px 16px 24px;
        overscroll-behavior: contain;
    }

    .editor-toolbar {
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
}

