:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1f2430;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

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

/* ---- Top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 18px; margin-left: 8px; }
.nav a { color: var(--muted); font-size: .93rem; }
.nav a:hover { color: var(--text); text-decoration: none; }
.topbar-search { margin-left: auto; }
.topbar-search input {
    width: 220px; max-width: 40vw; padding: 7px 12px; font-size: .88rem;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; font-family: inherit;
}
.topbar-search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.user-menu { display: flex; align-items: center; gap: 12px; }
.username { font-size: .9rem; color: var(--muted); }
.badge { background: var(--primary); color: #fff; font-size: .68rem; padding: 2px 6px; border-radius: 6px; text-transform: uppercase; letter-spacing: .04em; }

/* ---- Layout ---- */
.container { max-width: 960px; margin: 0 auto; padding: 28px 24px 60px; }
.footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 24px; }

.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.5rem; margin: 0; }
.page-head .spacer { margin-left: auto; }

/* ---- Buttons ---- */
.btn {
    display: inline-block;
    border: 1px solid transparent;
    background: var(--primary);
    color: #fff;
    padding: 8px 15px;
    border-radius: 8px;
    font-size: .9rem;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.2;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: #f1f3f6; color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }

/* ---- Cards / lists ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 26px 0 10px; }

.list { list-style: none; margin: 0; padding: 0; }
.list-row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row .icon { font-size: 1.1rem; }
.list-row .main { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; }
.list-row .meta { font-size: .8rem; color: var(--muted); }
.list-row .actions { display: flex; gap: 8px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 14px; }
.tile {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
    display: block; color: var(--text);
}
.tile:hover { border-color: var(--primary); text-decoration: none; }
.tile .icon { font-size: 1.6rem; }
.tile .title { font-weight: 600; margin-top: 8px; word-break: break-word; }
.tile .meta { font-size: .78rem; color: var(--muted); margin-top: 4px; }

/* ---- Forms ---- */
.form { max-width: 420px; }
.form.card { padding: 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border);
    border-radius: 8px; font-size: .95rem; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.inline-form { display: inline; }

/* ---- Flash ---- */
.flash { padding: 11px 15px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.flash-info { background: #e0edff; color: #1e40af; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* ---- Auth screen ---- */
.auth-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h1 { text-align: center; margin-bottom: 4px; }
.auth-box .subtitle { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: .9rem; }

/* ---- Tables ---- */
table.data { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data th, table.data td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: .9rem; }
table.data th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }

/* ---- Editor ---- */
.editor-toolbar {
    display: flex; flex-wrap: wrap; gap: 4px;
    background: var(--surface); border: 1px solid var(--border);
    border-bottom: none; border-radius: var(--radius) var(--radius) 0 0;
    padding: 8px;
}
.editor-toolbar button {
    min-width: 34px; height: 32px; border: 1px solid transparent; background: transparent;
    border-radius: 6px; cursor: pointer; font-size: .9rem; color: var(--text); padding: 0 8px;
}
.editor-toolbar button:hover { background: #f1f3f6; }
.editor-toolbar .sep { width: 1px; background: var(--border); margin: 2px 4px; }
.editor-surface {
    background: #fff; border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
    min-height: 55vh; padding: 24px 28px; outline: none; font-size: 1rem;
}
.editor-surface:focus { border-color: var(--primary); }
.editor-surface h1 { font-size: 1.6rem; }
.editor-surface h2 { font-size: 1.3rem; }
.editor-surface blockquote { border-left: 3px solid var(--border); margin: 0; padding-left: 14px; color: var(--muted); }
.editor-surface pre { background: #f6f8fa; padding: 12px; border-radius: 8px; overflow: auto; }

.doc-content { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 36px; box-shadow: var(--shadow); }
.doc-content h1 { font-size: 1.6rem; }
.doc-content blockquote { border-left: 3px solid var(--border); margin: 0; padding-left: 14px; color: var(--muted); }
.doc-content pre { background: #f6f8fa; padding: 12px; border-radius: 8px; overflow: auto; }
.doc-content img { max-width: 100%; }

.muted { color: var(--muted); }
.save-status { font-size: .82rem; color: var(--muted); }

/* ---- Pagination ---- */
.pagination { display: flex; align-items: center; gap: 14px; justify-content: center; margin-top: 20px; }
.pagination .page-info { font-size: .85rem; color: var(--muted); }
.btn.disabled { opacity: .45; pointer-events: none; }

/* ---- Editor word count ---- */
.editor-count { font-size: .82rem; color: var(--muted); margin-top: 8px; text-align: right; }

/* ---- Tags ---- */
.tag-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0 14px; }
.tag {
    display: inline-flex; align-items: center; gap: 4px;
    background: #eef2ff; color: #3730a3; border-radius: 999px;
    padding: 3px 10px; font-size: .8rem; line-height: 1.4;
}
.tag a { color: inherit; }
.tag a:hover { text-decoration: none; }
.tag-remove {
    border: none; background: transparent; color: #6366f1; cursor: pointer;
    font-size: 1rem; line-height: 1; padding: 0 0 0 2px;
}
.tag-remove:hover { color: var(--danger); }
.tag-mini { margin-left: 8px; padding: 1px 8px; font-size: .72rem; }
.tag-add input {
    border: 1px dashed var(--border); border-radius: 999px; padding: 3px 12px;
    font-size: .8rem; font-family: inherit; background: #fff; width: 130px;
}
.tag-add input:focus { outline: none; border-color: var(--primary); border-style: solid; }

/* ---- Version diff ---- */
.diff-view { line-height: 1.9; }
.diff-view ins { background: #dcfce7; color: #166534; text-decoration: none; padding: 1px 2px; border-radius: 3px; }
.diff-view del { background: #fee2e2; color: #991b1b; text-decoration: line-through; padding: 1px 2px; border-radius: 3px; }
.diff-legend { float: right; font-weight: 400; text-transform: none; letter-spacing: 0; font-size: .72rem; color: var(--muted); }
.diff-ins-swatch, .diff-del-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 3px 0 10px; vertical-align: middle; }
.diff-ins-swatch { background: #dcfce7; }
.diff-del-swatch { background: #fee2e2; }

/* ---- Team tags ---- */
.tag-team { background: #fef3c7; color: #92400e; }
.tag-team .tag-remove { color: #b45309; }

/* ---- Move-to-folder bar ---- */
.move-bar { margin: 4px 0 10px; }
.move-bar select {
    border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px;
    font-family: inherit; font-size: .85rem; margin-left: 4px;
}

/* ---- Search results ---- */
.snippet { font-size: .88rem; color: #4b5563; margin: 3px 0; }
mark { background: #fde68a; color: inherit; padding: 0 1px; border-radius: 2px; }

/* ---- Print ---- */
@media print {
    .topbar, .footer, .no-print, .tag-remove, .tag-add { display: none !important; }
    body { background: #fff; }
    .container { max-width: 100%; padding: 0; }
    .doc-content { border: none; box-shadow: none; padding: 0; }
    a { color: #000; text-decoration: none; }
    .tag { background: #eee; color: #000; }
}
