/* ============================================================
   Naqsh — Stylesheet
   ============================================================ */

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

:root {
    --bg: #faf8f3;
    --surface: #ffffff;
    --surface-2: #f3f0e8;
    --surface-3: #ebe7da;
    --border: rgba(20, 20, 20, 0.08);
    --border-strong: rgba(20, 20, 20, 0.18);
    --text: #1a1a1a;
    --text-muted: #6a6862;
    --text-subtle: #9a9892;
    --accent: #b45309;
    --accent-bg: #fef3c7;
    --accent-border: #fbbf24;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --success: #15803d;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 2px 8px rgba(0,0,0,0.06);

    --topbar-h: 56px;
    --capture-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
    font-family: inherit;
    cursor: pointer;
}

input, textarea, button, select {
    font-family: inherit;
    font-size: inherit;
}

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.brand {
    margin: 0 0 0.25rem;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
}
.brand span {
    color: var(--accent);
    font-weight: 500;
    margin-right: 0.5rem;
}

.muted { color: var(--text-muted); margin: 0 0 1.5rem; }
.muted.small { font-size: 0.85rem; }

.alert {
    background: var(--danger-bg);
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.auth-card label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.auth-card input {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 0.7rem 0.9rem;
    font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-card input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

.btn-primary {
    margin-top: 1.25rem;
    background: var(--text);
    color: var(--surface);
    border: none;
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.95rem;
    transition: opacity 0.15s, transform 0.05s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.99); }

.auth-link {
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
}

code {
    background: var(--surface-2);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: ui-monospace, monospace;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app-body {
    background: var(--bg);
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-inner {
    max-width: 1400px;
    height: 100%;
    margin: 0 auto;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.brand-mini {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}
.brand-mini span {
    color: var(--accent);
    font-weight: 500;
    margin-right: 0.3rem;
    font-size: 0.95rem;
}

.search-wrap {
    flex: 1;
    max-width: 480px;
}

.search-wrap input {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    transition: border-color 0.15s, background 0.15s;
}
.search-wrap input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--border-strong);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-right: auto;
}
.user-name {
    font-size: 0.9rem;
    color: var(--text-muted);
}
.logout-link {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.logout-link:hover { color: var(--danger); }

/* ----- Capture bar ----- */
.capture-bar {
    background: var(--accent-bg);
    border-bottom: 1px solid var(--accent-border);
    height: var(--capture-h);
}
.capture-inner {
    max-width: 1400px;
    height: 100%;
    margin: 0 auto;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.capture-icon { font-size: 1.1rem; }
.capture-label {
    font-size: 0.85rem;
    color: #92400e;
    font-weight: 500;
    white-space: nowrap;
}
#captureInput {
    flex: 1;
    background: var(--surface);
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 0.5rem 0.9rem;
    font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
#captureInput:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.15);
}
.btn-mini {
    background: var(--text);
    color: var(--surface);
    border: none;
    padding: 0.45rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
}
.btn-mini:hover { opacity: 0.9; }

/* ----- Layout ----- */
.layout {
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1.25rem;
    padding: 1.25rem;
}

.sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 0.75rem;
    align-self: start;
    position: sticky;
    top: calc(var(--topbar-h) + var(--capture-h) + 1.25rem);
}

.side-section { margin-bottom: 1.25rem; }
.side-section:last-child { margin-bottom: 0; }

.side-label {
    font-size: 0.72rem;
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.25rem 0.6rem;
    margin-bottom: 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.add-mini {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 22px;
    height: 22px;
    border-radius: 6px;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}
.add-mini:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.92rem;
    color: var(--text);
    margin-bottom: 1px;
    transition: background 0.12s;
    user-select: none;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active {
    background: var(--surface-3);
    font-weight: 500;
}
.nav-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}
.nav-count {
    font-size: 0.75rem;
    color: var(--text-subtle);
    background: var(--surface-2);
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
}
.nav-item.active .nav-count {
    background: var(--surface);
}

/* ----- Content area ----- */
.content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.75rem;
    min-height: 500px;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.view-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 0.25rem;
}
.view-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}
.view-actions { display: flex; gap: 0.5rem; }

.btn {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    transition: background 0.15s;
}
.btn:hover { background: var(--surface-2); }

.btn-danger {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--danger);
}
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }

/* ----- Note cards ----- */
.notes-grid { display: grid; gap: 0.75rem; }

.note-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    cursor: pointer;
    position: relative;
}
.note-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}
.note-card.pinned {
    background: #fffbeb;
    border-color: var(--accent-border);
}

.note-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
    color: var(--text-subtle);
    margin-bottom: 0.4rem;
}
.note-actions { display: flex; gap: 0.3rem; }
.note-action {
    background: transparent;
    border: none;
    color: var(--text-subtle);
    font-size: 0.78rem;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}
.note-action:hover { background: var(--surface-2); color: var(--text); }
.note-action.danger:hover { background: var(--danger-bg); color: var(--danger); }

.note-title {
    font-weight: 500;
    font-size: 1rem;
    margin: 0 0 0.3rem;
    color: var(--text);
}
.note-body {
    font-size: 0.92rem;
    color: var(--text-muted);
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
}

.empty-state {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
}
.empty-state strong { color: var(--text); }

/* ----- Editor ----- */
.editor {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.editor input.editor-title {
    background: transparent;
    border: none;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
    padding: 0.5rem 0;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s;
}
.editor input.editor-title:focus {
    outline: none;
    border-bottom-color: var(--border);
}
.editor textarea.editor-content {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.7;
    min-height: 320px;
    resize: vertical;
    color: var(--text);
}
.editor textarea.editor-content:focus {
    outline: none;
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px var(--accent-bg);
}
.editor-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.5rem;
    color: var(--text-subtle);
    font-size: 0.82rem;
}
.editor-bar .actions { display: flex; gap: 0.5rem; }

/* ----- Modal ----- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal-backdrop.hidden { display: none; }
.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.75rem;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.modal h3 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    font-weight: 700;
}
.modal-form { display: flex; flex-direction: column; gap: 0.5rem; }
.modal-form label { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.5rem; }
.modal-form input, .modal-form select, .modal-form textarea {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 0.6rem 0.85rem;
    font-size: 0.92rem;
}
.modal-form input:focus, .modal-form select:focus, .modal-form textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}
.modal-actions {
    margin-top: 1.25rem;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-start;
}

/* ----- Toast ----- */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--surface);
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: opacity 0.2s, transform 0.2s;
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(8px); }

/* ----- Responsive ----- */
@media (max-width: 768px) {
    .layout {
        grid-template-columns: 1fr;
        padding: 0.75rem;
    }
    .sidebar { position: static; }
    .topbar-inner { gap: 0.75rem; padding: 0 0.75rem; }
    .search-wrap { display: none; }
    .capture-inner { padding: 0 0.75rem; gap: 0.5rem; }
    .capture-label { display: none; }
    .content { padding: 1rem 1.1rem; }
}
