/* =========================================================================
   Oblivion — global app shell styles
   Vault-provided theme.css (injected as <style id="vault-theme">) owns
   colour variables and heading typography. Everything below builds on
   those CSS variables.
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--obv-bg);
    color: var(--obv-text);
    font-family: var(--obv-font);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--obv-link); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
    cursor: pointer;
    font: inherit;
    color: inherit;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 6px 10px;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}
button:hover { background: color-mix(in srgb, var(--obv-accent) 14%, transparent); }
button:active { transform: translateY(1px); }

input, textarea, select {
    font: inherit;
    color: inherit;
    background: var(--obv-surface);
    border: 1px solid var(--obv-border);
    border-radius: 8px;
    padding: 9px 12px;
    width: 100%;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--obv-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--obv-accent) 22%, transparent);
}
select {
    appearance: none;
    background-image:
      linear-gradient(45deg, transparent 50%, var(--obv-muted) 50%),
      linear-gradient(135deg, var(--obv-muted) 50%, transparent 50%);
    background-position: right 14px center, right 10px center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 30px;
}
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.welcome__library {
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--obv-muted);
}
.welcome__library code {
    word-break: break-all;
}

code {
    font-family: var(--obv-mono);
    background: var(--obv-code-bg);
    padding: 1px 6px;
    border-radius: 5px;
    font-size: 0.9em;
}

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
    background: var(--obv-surface);
    border: 1px solid var(--obv-border);
    padding: 9px 16px;
    border-radius: 10px;
    font-weight: 500;
}
.btn:hover { border-color: var(--obv-accent); }
.btn.primary {
    background: color-mix(in srgb, var(--obv-accent) 85%, transparent);
    color: #1a1a22;
    border-color: transparent;
    font-weight: 600;
}
.btn.primary:hover { background: var(--obv-accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--obv-muted); }
.btn.ghost:hover { color: var(--obv-text); background: var(--obv-surface); }
.btn-link {
    background: none; border: none; padding: 0;
    color: var(--obv-link);
    text-decoration: underline;
    font: inherit;
}

.muted { color: var(--obv-muted); }
.small { font-size: 0.85em; }
.error {
    background: color-mix(in srgb, #ff6b6b 18%, transparent);
    border: 1px solid color-mix(in srgb, #ff6b6b 60%, transparent);
    color: #ffb3b3;
    padding: 8px 12px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: .92em;
}
.row { display: flex; gap: 10px; margin-top: 12px; }

/* =========================================================================
   App shell
   ========================================================================= */
.app-shell { min-height: 100vh; }
.app-main { min-height: 100vh; }

/* =========================================================================
   Welcome screen
   ========================================================================= */
.welcome {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 40px 20px;
    background:
        radial-gradient(circle at 20% 0%,  color-mix(in srgb, var(--obv-accent) 15%, transparent), transparent 45%),
        radial-gradient(circle at 80% 100%, color-mix(in srgb, #ffb4a2 18%, transparent), transparent 45%),
        var(--obv-bg);
}
.welcome__hero {
    max-width: 960px; width: 100%;
    display: flex; flex-direction: column; gap: 28px;
}
.welcome__brand { text-align: center; margin-bottom: 10px; }
.welcome__logo {
    font-size: 46px;
    color: var(--obv-accent);
    letter-spacing: -2px;
    animation: logo-pulse 4s ease-in-out infinite;
}
@keyframes logo-pulse {
    0%, 100% { text-shadow: 0 0 10px color-mix(in srgb, var(--obv-accent) 40%, transparent); }
    50%      { text-shadow: 0 0 30px color-mix(in srgb, var(--obv-accent) 60%, transparent); }
}
.welcome__title {
    font-size: 2.6rem;
    margin: 6px 0 4px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.welcome__tagline { color: var(--obv-muted); font-size: 1.05rem; }

.welcome__panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}
@media (max-width: 760px) { .welcome__panels { grid-template-columns: 1fr; } }

.welcome__panel {
    background: var(--obv-surface);
    border: 1px solid var(--obv-border);
    border-radius: 16px;
    padding: 22px 22px 20px;
    backdrop-filter: blur(6px);
}
.welcome__panel h2 {
    margin: 0 0 4px;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--obv-accent);
}
.welcome__panel .field { margin-top: 14px; }
.welcome__panel label {
    display: block;
    font-size: 0.82rem;
    color: var(--obv-muted);
    margin-bottom: 5px;
}
.welcome__panel .toggle-row label {
    display: inline-flex; align-items: center; gap: 8px;
    color: var(--obv-text);
    font-size: 0.95rem;
}
.welcome__panel .toggle-row input {
    width: auto;
}

.welcome__recent {
    background: var(--obv-surface);
    border: 1px solid var(--obv-border);
    border-radius: 16px;
    padding: 18px 22px;
}
.welcome__recent h2 {
    margin: 0 0 10px;
    font-size: 1.05rem;
    color: var(--obv-accent);
}
.recent-list {
    list-style: none; padding: 0; margin: 0;
    display: flex; flex-direction: column; gap: 4px;
}
.recent-list__item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s ease;
}
.recent-list__item:hover { background: color-mix(in srgb, var(--obv-accent) 10%, transparent); }
.recent-list__icon { font-size: 20px; color: var(--obv-accent); }
.recent-list__name { font-weight: 500; }
.recent-list__path { font-size: 0.82rem; color: var(--obv-muted); }
.recent-list__time { color: var(--obv-muted); font-size: 0.85rem; }

/* =========================================================================
   Workbench layout (editor page)
   ========================================================================= */
.workbench {
    display: grid;
    grid-template-columns: 300px 1fr;
    height: 100vh;
    min-height: 0;
}
.workbench__sidebar {
    background: var(--obv-sidebar);
    border-right: 1px solid var(--obv-border);
    display: flex; flex-direction: column;
    min-height: 0;
}
.workbench__main {
    display: flex; flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--obv-bg);
}

.sidebar__head {
    padding: 14px 14px 10px;
    border-bottom: 1px solid var(--obv-border);
}
.sidebar__vault {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}
.sidebar__vault-icon {
    font-size: 22px; color: var(--obv-accent);
}
.sidebar__vault-name { font-weight: 600; }
.sidebar__vault-path {
    font-size: 0.76rem;
    color: var(--obv-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar__actions {
    display: flex; gap: 4px;
    justify-content: flex-end;
}
.sidebar__actions button {
    font-size: 15px;
    padding: 4px 8px;
    color: var(--obv-muted);
    border-radius: 6px;
}
.sidebar__actions button:hover { color: var(--obv-text); background: var(--obv-surface); }

.sidebar__tree {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 6px 12px;
    min-height: 0;
}
.sidebar__foot {
    border-top: 1px solid var(--obv-border);
    padding: 10px 12px;
    display: flex; flex-direction: column; gap: 4px;
}

/* =========================================================================
   Folder tree
   ========================================================================= */
.tree {
    list-style: none;
    padding: 0;
    margin: 0;
    padding-left: 14px;
}
.tree--root { padding-left: 4px; }
.tree__item { margin: 0; }
.tree__row {
    display: grid;
    grid-template-columns: 16px 18px 1fr auto;
    gap: 6px;
    align-items: center;
    padding: 5px 8px;
    border-radius: 7px;
    cursor: pointer;
    transition: background .12s ease;
    position: relative;
}
.tree__row:hover {
    background: color-mix(in srgb, var(--obv-accent) 12%, transparent);
}
.tree__item.is-selected > .tree__row {
    background: color-mix(in srgb, var(--obv-accent) 22%, transparent);
}
.tree__chevron {
    font-size: 10px;
    color: var(--obv-muted);
    transition: transform .15s ease;
}
.tree__chevron.open { transform: rotate(90deg); }
.tree__chevron.placeholder { visibility: hidden; }
.tree__icon { font-size: 14px; opacity: 0.9; }
.tree__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tree__actions {
    opacity: 0;
    display: flex; gap: 2px;
    transition: opacity .1s ease;
}
.tree__row:hover .tree__actions { opacity: 1; }
.tree__actions button {
    font-size: 11px;
    padding: 2px 6px;
    color: var(--obv-muted);
    border-radius: 5px;
}
.tree__actions button:hover { color: var(--obv-text); background: var(--obv-bg); }

/* ----- Drag & drop ---------------------------------------------------- */
.tree__row[draggable="true"] { cursor: grab; }
.tree__row[draggable="true"]:active { cursor: grabbing; }

/* Highlight the folder row that is the current drop target. */
.tree__item.is-drop-target > .tree__row {
    background: color-mix(in srgb, var(--obv-accent) 30%, transparent);
    outline: 2px dashed var(--obv-accent);
    outline-offset: -2px;
    border-radius: 7px;
}
/* Highlight the whole sidebar tree when dropping at the vault root. */
.sidebar__tree.is-drop-target {
    outline: 2px dashed var(--obv-accent);
    outline-offset: -6px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--obv-accent) 6%, transparent);
}
.sidebar__drop-error {
    margin: 10px 12px 0;
    padding: 8px 10px;
    background: color-mix(in srgb, #ff6b6b 14%, transparent);
    border: 1px solid color-mix(in srgb, #ff6b6b 55%, transparent);
    border-radius: 8px;
    color: #ffb3b3;
    font-size: 0.82rem;
}

/* =========================================================================
   Editor area
   ========================================================================= */
.editor__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 18px;
    border-bottom: 1px solid var(--obv-border);
    background: var(--obv-sidebar);
}
.tabs { display: flex; gap: 4px; }
.tab {
    padding: 6px 14px;
    border-radius: 999px;
    color: var(--obv-muted);
    font-weight: 500;
    font-size: 0.92rem;
}
.tab.active {
    background: color-mix(in srgb, var(--obv-accent) 20%, transparent);
    color: var(--obv-text);
}
.editor__status {
    display: flex; align-items: center; gap: 14px;
    font-size: 0.88rem;
    color: var(--obv-muted);
}
.editor__title { color: var(--obv-text); font-weight: 500; }
.editor__save { font-variant-numeric: tabular-nums; }
.editor__save.dirty { color: #ffd6a5; }
.editor__collab {
    padding: 2px 10px;
    background: color-mix(in srgb, var(--obv-accent) 22%, transparent);
    border: 1px solid color-mix(in srgb, var(--obv-accent) 45%, transparent);
    border-radius: 999px;
    color: var(--obv-text);
    font-size: 0.78rem;
    max-width: 360px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    animation: collab-pop 0.25s ease-out;
}
@keyframes collab-pop {
    from { transform: scale(.96); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.editor__body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
}
.editor__textarea {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    resize: none;
    border: none;
    border-radius: 0;
    padding: 28px 6vw;
    background: var(--obv-bg);
    font-family: var(--obv-mono);
    font-size: 15px;
    line-height: 1.65;
    outline: none;
}
.editor__textarea:focus { box-shadow: none; border: none; }

.editor__reading {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 40px 6vw 80px;
}

.pane--theme {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 28px 6vw 60px;
}

/* =========================================================================
   Markdown rendering
   ========================================================================= */
.md-body {
    max-width: 780px;
    margin: 0 auto;
    word-wrap: break-word;
}
.md-body > :first-child { margin-top: 0; }
.md-body p { margin: 0 0 1em; }
.md-body h1, .md-body h2, .md-body h3,
.md-body h4, .md-body h5, .md-body h6 {
    margin: 1.4em 0 .5em;
    line-height: 1.25;
    letter-spacing: -0.01em;
}
.md-body h1:first-child { margin-top: 0; }
.md-body ul, .md-body ol { padding-left: 1.6em; }
.md-body li + li { margin-top: 0.25em; }
.md-body blockquote {
    border-left: 3px solid var(--obv-accent);
    padding: 4px 14px;
    color: var(--obv-muted);
    margin: 0 0 1em;
    background: color-mix(in srgb, var(--obv-accent) 6%, transparent);
    border-radius: 0 6px 6px 0;
}
.md-body pre {
    background: var(--obv-code-bg);
    padding: 14px 16px;
    border-radius: 10px;
    overflow-x: auto;
    font-family: var(--obv-mono);
    font-size: 0.88rem;
    line-height: 1.55;
    border: 1px solid var(--obv-border);
}
.md-body pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
}
.md-body table {
    border-collapse: collapse;
    margin: 1em 0;
    width: 100%;
}
.md-body th, .md-body td {
    border: 1px solid var(--obv-border);
    padding: 7px 10px;
    text-align: left;
}
.md-body th {
    background: color-mix(in srgb, var(--obv-accent) 10%, transparent);
    font-weight: 600;
}
.md-body hr {
    border: none;
    border-top: 1px solid var(--obv-border);
    margin: 2em 0;
}
.md-body img {
    max-width: 100%;
    border-radius: 8px;
}

/* =========================================================================
   Theme editor
   ========================================================================= */
.theme-editor {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 22px;
}
.theme-editor__section {
    background: var(--obv-surface);
    border: 1px solid var(--obv-border);
    border-radius: 14px;
    padding: 18px 20px;
}
.theme-editor__section h3 {
    margin: 0 0 12px;
    font-size: 1rem;
    color: var(--obv-accent);
    font-weight: 600;
}
.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
}
.color-field {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    font-size: 0.82rem;
    color: var(--obv-muted);
}
.color-field__controls {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 8px;
    align-items: center;
}
.color-field__controls input[type="color"] {
    padding: 0;
    height: 34px;
    width: 44px;
    border-radius: 8px;
    border: 1px solid var(--obv-border);
    background: transparent;
    cursor: pointer;
}
.color-field__controls input[type="text"] {
    padding: 6px 10px;
    font-family: var(--obv-mono);
    font-size: 0.82rem;
}
.heading-row {
    display: grid;
    grid-template-columns: 40px 44px 1fr 80px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.heading-row__tag {
    font-weight: 600;
    color: var(--obv-accent);
    text-align: center;
}
.heading-row__color {
    padding: 0;
    height: 34px;
    width: 44px;
    border-radius: 8px;
    border: 1px solid var(--obv-border);
    cursor: pointer;
}
.heading-row__size, .heading-row__weight {
    padding: 6px 10px;
    font-family: var(--obv-mono);
    font-size: 0.82rem;
}
.theme-editor__css {
    width: 100%;
    font-family: var(--obv-mono);
    font-size: 0.82rem;
    line-height: 1.55;
    min-height: 220px;
    resize: vertical;
}
.theme-editor__actions {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
}

/* =========================================================================
   Empty / error states
   ========================================================================= */
.empty-state {
    flex: 1 1 auto;
    display: flex; align-items: center; justify-content: center;
    padding: 40px;
    color: var(--obv-muted);
    text-align: center;
}
