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

:root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --border: #dee2e6;
    --text: #212529;
    --text-muted: #6c757d;
    --primary: #0d6efd;
    --primary-hover: #0b5ed7;
    --danger: #dc3545;
    --danger-hover: #bb2d3b;
    --success-bg: #d1e7dd;
    --success-text: #0f5132;
    --error-bg: #f8d7da;
    --error-text: #842029;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-width: 375px;
}

/* ── Header ──────────────────────────────────────────────── */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: .75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.site-title {
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
    color: var(--text);
    flex-shrink: 0;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    margin-left: auto;
}

.site-nav a {
    color: var(--primary);
    text-decoration: none;
    font-size: .9rem;
}

.site-nav a:hover { text-decoration: underline; }

.logout-form button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: .9rem;
    padding: 0;
}

.logout-form button:hover { color: var(--danger); }

/* ── Main ─────────────────────────────────────────────────── */
.site-main {
    max-width: 860px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: .4rem .9rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, color .15s;
    white-space: nowrap;
}

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

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

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }

.btn-sm { padding: .25rem .6rem; font-size: .8rem; }

/* ── Forms ────────────────────────────────────────────────── */
label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    font-size: .9rem;
    font-weight: 500;
    margin-bottom: .9rem;
}

input[type=text],
input[type=email],
input[type=password],
input[type=search],
textarea,
select {
    width: 100%;
    padding: .45rem .7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .95rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ── Auth box ─────────────────────────────────────────────── */
.auth-box {
    max-width: 400px;
    margin: 3rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.auth-box h1 { margin-bottom: 1.2rem; font-size: 1.4rem; }

.auth-box button[type=submit] {
    width: 100%;
    padding: .55rem;
    margin-top: .5rem;
}

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

/* ── Errors / success ─────────────────────────────────────── */
.errors {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid #f5c2c7;
    border-radius: var(--radius);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
    list-style: none;
}

.errors li + li { margin-top: .3rem; }

.success {
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid #badbcc;
    border-radius: var(--radius);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
}

/* ── Notes list ───────────────────────────────────────────── */
.notes-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1rem;
}

.notes-list-header h1 { font-size: 1.4rem; }

.search-form {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: .75rem;
    align-items: center;
}

.search-form input[type=search] { flex: 1; min-width: 200px; }

.search-meta { font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem; }

.empty-state { color: var(--text-muted); margin-top: 1.5rem; }

.notes-items { list-style: none; display: flex; flex-direction: column; gap: .5rem; }

.note-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

.note-link {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: .2rem .75rem;
    padding: .85rem 1rem;
    text-decoration: none;
    color: inherit;
}

.note-link:hover { background: var(--bg); }

.note-title { font-weight: 600; color: var(--text); grid-column: 1; }

.note-preview {
    font-size: .85rem;
    color: var(--text-muted);
    grid-column: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-date { font-size: .78rem; color: var(--text-muted); grid-row: 1; grid-column: 2; align-self: start; }

/* ── Note editor ──────────────────────────────────────────── */
.note-form-header {
    display: flex;
    gap: .75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: .75rem;
}

.note-title-input {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
    min-width: 200px;
}

.note-form-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* EasyMDE container */
.note-content { min-height: 400px; }

.CodeMirror { min-height: 400px; font-size: .95rem; }

/* ── Settings box ─────────────────────────────────────────── */
.settings-box { max-width: 640px; }

.settings-box h1 { font-size: 1.4rem; margin-bottom: 1.2rem; }
.settings-box h2 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; }

.settings-box button[type=submit] { margin-top: .25rem; }

/* ── Token reveal ─────────────────────────────────────────── */
.token-reveal {
    background: #fff3cd;
    border: 1px solid #ffecb5;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.token-reveal p { font-size: .9rem; margin-bottom: .5rem; }

.token-reveal code {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .5rem .75rem;
    font-size: .85rem;
    word-break: break-all;
    margin-bottom: .5rem;
}

.recovery-codes {
    list-style: none;
    padding-left: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .4rem;
    margin-bottom: .6rem;
}

.recovery-codes code {
    display: inline-block;
    font-size: .85rem;
}

/* ── Tokens table ─────────────────────────────────────────── */
.tokens-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .87rem;
    overflow-x: auto;
    display: block;
}

.tokens-table th,
.tokens-table td {
    padding: .55rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.tokens-table th { font-weight: 600; background: var(--bg); }

.token-revoked td { color: var(--text-muted); text-decoration: line-through; }
.token-revoked td:last-child { text-decoration: none; }

.token-form { margin-bottom: 1.5rem; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 500px) {
    .site-main { margin: 1rem auto; }
    .note-form-header { flex-direction: column; align-items: stretch; }
    .note-form-actions { justify-content: flex-end; }
    .auth-box { margin: 1.5rem auto; }
}
