/* Notes App - Google Keep style, full width, bilingual (EN/FA), animated.
   Palette: soft off-white + calm dark blue. */
:root {
    --bg:           #eef1f4; /* slightly dark white - easy on the eyes */
    --surface:      #f7f8fa;
    --surface-2:    #ffffff;
    --border:       #d8dee6;
    --text:         #243044;
    --muted:        #6b7685;
    --blue:         #34568b; /* calm dark blue, not too dark */
    --blue-dark:    #2a4673;
    --blue-soft:    #e3e9f3;
    --danger:       #b1495a;
    --danger-dark:  #8f3848;
    --radius:       12px;
    --shadow:       0 1px 3px rgba(36, 48, 68, 0.10);
    --shadow-hover: 0 4px 14px rgba(36, 48, 68, 0.18);
    --header-h:     56px;
    /* System font stacks (no external/Google fonts) */
    --font-en: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, Arial, sans-serif;
    --font-fa: "Segoe UI", Tahoma, "Iran Sans", system-ui, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-en);
    font-size: 16px;
    line-height: 1.5;
    margin: 0;
    overflow-x: hidden; /* never allow sideways scroll on mobile */
    -webkit-font-smoothing: antialiased;
}
/* Persian system font when RTL (Tahoma renders Persian well everywhere) */
html[dir="rtl"] body { font-family: var(--font-fa); }

/* ---------- Header (full width) ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.app-header-inner {
    height: var(--header-h);
    width: 100%;
    /* respect notch / rounded corners on phones */
    padding: 0 max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.app-brand {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--blue);
    text-decoration: none;
}
.app-brand:hover { color: var(--blue-dark); }
.app-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.app-user { color: var(--muted); font-size: .85rem; }

.lang-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: .82rem;
    color: var(--text);
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.lang-toggle:hover { background: var(--blue-soft); border-color: var(--blue); }
.lang-globe { font-size: .95rem; line-height: 1; }

/* ---------- Main (full width) ---------- */
.app-main {
    width: 100%;
    padding: 22px clamp(16px, 4vw, 64px) 60px;
}

/* ---------- Keep container ---------- */
.keep { width: 100%; }

.keep-search-wrap { display: flex; justify-content: center; margin-bottom: 22px; }
.keep-search {
    width: 100%;
    max-width: 560px;
    padding: 11px 18px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    outline: none;
    box-shadow: var(--shadow);
    transition: box-shadow .2s, border-color .2s;
}
.keep-search:focus { border-color: var(--blue); box-shadow: var(--shadow-hover); }

/* ---------- Composer ---------- */
.composer {
    width: 100%;
    max-width: 600px;
    margin: 0 auto 30px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: box-shadow .2s;
    overflow: hidden;
}
.composer:focus-within { box-shadow: var(--shadow-hover); }
.composer-collapsed {
    width: 100%;
    border: none;
    outline: none;
    padding: 14px 18px;
    font-size: 1rem;
    font-weight: 500;
    background: transparent;
    color: var(--text);
    cursor: text;
    font-family: inherit;
}
.composer-expanded { padding: 12px 16px 8px; animation: fadeIn .18s ease; }
.composer-title, .composer-content, .modal-content-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
}
.composer-title { font-size: 1.05rem; font-weight: 600; padding: 6px 2px; }
.composer-content {
    padding: 6px 2px;
    font-size: .95rem;
    line-height: 1.5;
    resize: none;
    min-height: 70px;
    max-height: 50vh;
}
.composer-actions { display: flex; justify-content: flex-end; padding: 4px; }

/* ---------- Buttons ---------- */
.btn-primary-blue, .btn-secondary, .btn-danger, .btn-text {
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: .88rem;
    cursor: pointer;
    transition: background .15s, transform .1s;
    font-family: inherit;
    text-decoration: none;
    display: inline-block;
}
.btn-primary-blue { background: var(--blue); color: #fff; }
.btn-primary-blue:hover { background: var(--blue-dark); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--blue-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-text { background: transparent; color: var(--text); font-weight: 600; }
.btn-text:hover { background: var(--bg); }
.btn-primary-blue:active, .btn-secondary:active, .btn-danger:active { transform: scale(.97); }

.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.05rem;
    padding: 7px;
    border-radius: 50%;
    line-height: 1;
    transition: background .15s;
}
.btn-icon:hover { background: var(--bg); }
.btn-delete:hover { background: #f6e4e7; }

.status-msg { font-size: .8rem; color: var(--blue); }

/* ---------- Masonry grid ---------- */
.keep-grid {
    column-gap: 16px;
    columns: 5 220px;
}
.note-card {
    break-inside: avoid;
    margin: 0 0 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: box-shadow .18s, transform .18s;
    animation: cardIn .25s ease both;
}
.note-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.note-card .card-title {
    font-weight: 600;
    margin: 0 0 6px;
    word-break: break-word;
}
.note-card .card-preview {
    color: var(--text);
    font-size: .9rem;
    line-height: 1.5;
    margin: 0 0 10px;
    white-space: pre-wrap;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 10;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.note-card .card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    opacity: 0;
    transition: opacity .15s;
}
.note-card:hover .card-footer { opacity: 1; }
.note-card .card-date { color: var(--muted); font-size: .72rem; }

/* ---------- Loading ---------- */
.keep-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
    padding: 50px 0;
    animation: fadeIn .2s ease;
}
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--blue-soft);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

/* ---------- Empty ---------- */
.keep-empty {
    text-align: center;
    color: var(--muted);
    padding: 60px 0;
    animation: fadeIn .25s ease;
}
.keep-empty-icon { font-size: 3rem; opacity: .5; margin-bottom: 10px; }

/* ---------- Modal editor ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(36, 48, 68, .45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 16px;
    z-index: 1000;
    animation: fadeIn .15s ease;
}
.modal-note {
    background: var(--surface-2);
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    padding: 16px 18px 8px;
    box-shadow: 0 12px 40px rgba(36, 48, 68, .3);
    animation: modalIn .2s ease;
    display: flex;
    flex-direction: column;
}
.modal-content-input {
    font-size: .98rem;
    line-height: 1.55;
    resize: none;
    min-height: 200px;
    max-height: 55vh;
    padding: 8px 2px;
}
.modal-meta { color: var(--muted); font-size: .74rem; padding: 6px 2px; }
.modal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
}
.modal-actions .btn-text { margin-inline-start: auto; }

/* ---------- Confirm dialog ---------- */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(36, 48, 68, .35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    animation: fadeIn .15s ease;
}
.confirm-box {
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 22px;
    max-width: 360px;
    width: 90%;
    box-shadow: 0 8px 24px rgba(36, 48, 68, .2);
    text-align: center;
    animation: modalIn .2s ease;
}
.confirm-actions { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }

/* ---------- Auth / login ---------- */
.auth-wrap { display: flex; justify-content: center; align-items: flex-start; padding-top: 8vh; }
.auth-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 30px;
    width: 100%;
    max-width: 380px;
    text-align: center;
    animation: modalIn .25s ease;
}
.auth-logo { font-size: 1.6rem; font-weight: 700; color: var(--blue); margin: 0; }
.auth-sub { color: var(--muted); font-size: .9rem; margin: 4px 0 18px; }
.auth-form { display: flex; flex-direction: column; gap: 4px; text-align: start; }
.auth-label { font-size: .82rem; color: var(--text); margin-bottom: 2px; }
.auth-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    outline: none;
    transition: border-color .15s;
}
.auth-input:focus { border-color: var(--blue); }
.auth-btn { margin-top: 12px; width: 100%; }
.field-error { color: var(--danger); font-size: .78rem; }

/* ---------- Animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes cardIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(-12px) scale(.97); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */

/* Tablets / small laptops */
@media (max-width: 1024px) {
    .keep-grid { columns: 3 200px; }
    .app-main { padding: 18px clamp(12px, 3vw, 32px) 50px; }
}

/* Phones */
@media (max-width: 600px) {
    :root { --header-h: 52px; }

    body { font-size: 15px; }

    /* page padding respects the notch + home-indicator area */
    .app-main {
        padding:
            14px
            max(12px, env(safe-area-inset-right))
            calc(48px + env(safe-area-inset-bottom))
            max(12px, env(safe-area-inset-left));
    }
    .app-header-inner { padding: 0 max(12px, env(safe-area-inset-left)); }
    .app-brand { font-size: 1.2rem; }
    .app-user { display: none; }
    .app-header-actions { gap: 8px; }
    .lang-toggle { padding: 6px 10px; font-size: .8rem; }

    /* Single-column feed, comfortable spacing */
    .keep-grid { columns: 1; column-gap: 0; }
    .note-card { margin-bottom: 12px; padding: 14px 16px; }
    /* Always show card actions on touch (no hover) */
    .note-card .card-footer { opacity: 1; }
    .note-card .card-preview { font-size: .95rem; -webkit-line-clamp: 8; }

    .keep-search, .composer { max-width: 100%; }
    .keep-search-wrap { margin-bottom: 16px; }
    .composer { margin-bottom: 22px; }

    /* 16px inputs prevent iOS auto-zoom on focus */
    .keep-search,
    .composer-collapsed,
    .composer-title,
    .composer-content,
    .modal-content-input,
    .auth-input,
    .note-title-input { font-size: 16px; }

    /* Modal becomes a near-full-screen sheet */
    .modal-overlay { padding: 0; align-items: stretch; }
    .modal-note {
        max-width: 100%;
        min-height: 100%;
        border-radius: 0;
        padding: 16px 16px 10px;
    }
    .modal-note {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
    .modal-content-input { min-height: 50vh; max-height: none; }

    /* Bigger, finger-friendly tap targets */
    .btn-primary-blue, .btn-secondary, .btn-danger, .btn-text { padding: 10px 18px; }
    .btn-icon { padding: 9px; font-size: 1.15rem; }

    /* Confirm + auth fill the width nicely */
    .confirm-box { padding: 20px; }
    .auth-wrap { padding-top: 0; align-items: stretch; min-height: calc(100vh - var(--header-h)); }
    .auth-card {
        padding: 24px 20px;
        border-radius: 0;
        box-shadow: none;
        max-width: 100%;
        /* fill the screen and center the form vertically */
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}

/* Very small phones */
@media (max-width: 380px) {
    .app-brand { font-size: 1.1rem; }
    .lang-toggle .lang-globe { display: none; } /* keep just the language label */
    .note-card { padding: 12px 14px; }
}

/* Short landscape (small phones rotated): don't force tall full-screen sheets */
@media (max-height: 480px) and (orientation: landscape) {
    .modal-overlay { padding: 12px; align-items: center; }
    .modal-note { min-height: auto; border-radius: var(--radius); }
    .modal-content-input { min-height: 30vh; }
    .auth-wrap { padding-top: 2vh; }
    .auth-card { min-height: auto; }
}

/* Honor reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
