/*
 * Mailworkflow theme. Keeps the familiar structure of the original tool
 * (columns-per-person, 3 stacked tables, status-by-colour, German labels) but
 * modernises the chrome: soft card surfaces, real spacing, subtle borders and
 * shadows, muted table headers, and properly styled form controls. Warm "paper"
 * palette from docs/reference/v1-design-reconstruction.md, light/dark aware.
 */
:root {
    --paper: #f2efe8;
    --ink: #262320;
    --ink-soft: #4b4741;
    --accent: #3a6b70;
    --accent-strong: #2c565a;
    --accent-soft: #e4eef0;
    --line: #e0d8ca;
    --line-strong: #cfc5b3;
    --card: #fffdf9;
    --card-raised: #ffffff;
    --muted: #8a8378;
    --crit: #b23b3b;
    --crit-soft: #f7e4e0;
    --warn: #9a5b00;
    --good: #2f6d42;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 2px rgba(38, 35, 32, .05), 0 2px 8px rgba(38, 35, 32, .06);
    --shadow-raised: 0 2px 4px rgba(38, 35, 32, .06), 0 8px 24px rgba(38, 35, 32, .08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #171614;
        --ink: #ece7dd;
        --ink-soft: #b8b2a6;
        --accent: #83b4b8;
        --accent-strong: #9ac6ca;
        --accent-soft: #223032;
        --line: #322e28;
        --line-strong: #423d35;
        --card: #201e1b;
        --card-raised: #262320;
        --muted: #948d81;
        --crit: #e58f8f;
        --crit-soft: #3a201e;
        --warn: #d6a04a;
        --good: #82c496;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .35);
        --shadow-raised: 0 2px 6px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .5);
    }
}

:root[data-theme="dark"] {
    --paper: #171614; --ink: #ece7dd; --ink-soft: #b8b2a6; --accent: #83b4b8;
    --accent-strong: #9ac6ca; --accent-soft: #223032; --line: #322e28;
    --line-strong: #423d35; --card: #201e1b; --card-raised: #262320;
    --muted: #948d81; --crit: #e58f8f; --crit-soft: #3a201e; --warn: #d6a04a; --good: #82c496;
}
:root[data-theme="light"] {
    --paper: #f2efe8; --ink: #262320; --ink-soft: #4b4741; --accent: #3a6b70;
    --accent-strong: #2c565a; --accent-soft: #e4eef0; --line: #e0d8ca;
    --line-strong: #cfc5b3; --card: #fffdf9; --card-raised: #ffffff;
    --muted: #8a8378; --crit: #b23b3b; --crit-soft: #f7e4e0; --warn: #9a5b00; --good: #2f6d42;
}

* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--paper);
    color: var(--ink);
    margin: 0;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

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

h2 { font-size: 1.25rem; font-weight: 650; letter-spacing: -.01em; margin: 0 0 .8rem; }
h3 { font-size: 1rem; font-weight: 650; margin: 1.4rem 0 .5rem; }

/* --- App bar: one slim row across the very top ---------------------------- */
/* Permanent top menu (templates/_nav.html.twig). It is the sticky bar; the
   per-page .app-header below it scrolls with the page. */
.app-nav {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
    padding: .35rem 1rem;
    background: var(--accent);
    font-size: .85rem;
}
.app-nav a { color: #fff; font-weight: 600; }
.app-nav a:hover { text-decoration: underline; }
.app-nav .brand { font-weight: 700; letter-spacing: -.02em; }
.app-nav .version { font-weight: 500; font-size: .75rem; opacity: .8; }
.app-nav .links { display: flex; gap: 1rem; flex-wrap: wrap; }
.app-nav .who { margin-left: auto; display: flex; gap: 1rem; }

.app-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .3rem 1rem;
    min-height: 2.4rem;
    background: color-mix(in srgb, var(--card) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--line);
}

.app-header > strong {
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--ink);
}

.app-header .who {
    font-size: .85rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
}

.app-header a { color: var(--accent); font-weight: 600; }

.app-main {
    padding: 1.75rem 1.5rem;
    max-width: 960px;
    margin: 0 auto;
}
.app-main--narrow { max-width: 640px; }
.app-main--wide { max-width: none; padding: 1rem; }

/* --- Form controls ------------------------------------------------------- */
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], input[type=date], textarea, select {
    font: inherit;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: .5rem .65rem;
    transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
label { font-size: .85rem; color: var(--ink-soft); }

/* Buttons: default = subtle; .btn-primary = accent. Bare <button> in forms too. */
button, .btn {
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--line-strong);
    background: var(--card-raised);
    color: var(--ink);
    padding: .5rem .9rem;
    border-radius: var(--radius-sm);
    transition: background .12s, border-color .12s, transform .05s;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button:active, .btn:active { transform: translateY(1px); }

.btn-primary, button[type=submit] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover, button[type=submit]:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    color: #fff;
}

/* --- Status colours (must-keep at-a-glance signal) ----------------------- */
.status-red, .status-green, .status-grey {
    display: inline-block;
    font-weight: 600;
    font-size: .78rem;
    padding: .1rem .5rem;
    border-radius: 999px;
    line-height: 1.4;
}
.status-red { color: var(--crit); background: var(--crit-soft); }
.status-green { color: var(--good); background: color-mix(in srgb, var(--good) 16%, transparent); }
.status-grey { color: var(--muted); background: color-mix(in srgb, var(--muted) 16%, transparent); }

/* --- Tables (generic; dashboard has its own denser variant) -------------- */
table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
th {
    background: var(--accent-soft);
    color: var(--accent-strong);
    text-align: left;
    padding: .55rem .8rem;
    font-size: .72rem;
    font-weight: 650;
    letter-spacing: .04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
}
td {
    border-bottom: 1px solid var(--line);
    padding: .55rem .8rem;
    font-size: .9rem;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }

.code { font-family: ui-monospace, "SF Mono", "Courier New", monospace; font-weight: 600; }

.muted-note { color: var(--muted); font-size: .85rem; margin-top: 1rem; }

.tenant-line { font-size: 1.05rem; margin-bottom: 1.25rem; }
.tenant-line strong { color: var(--accent); }

/* Link styled as a button (e.g. "Bearbeiter", "Aendern"). */
.link-btn {
    display: inline-block; padding: .3rem .8rem;
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    color: var(--ink); background: var(--card-raised); font-weight: 600;
}
.link-btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* Attachment drop zone (templates/task/_macros.html.twig, dropzone_controller.js). */
.dropzone {
    margin: 1.1rem 0 .6rem; padding: 1rem; text-align: center;
    border: 2px dashed var(--line-strong); border-radius: var(--radius-sm);
    color: var(--muted); font-size: .9rem; cursor: pointer;
}
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.dropzone input[type=file] { display: none; }
.dropzone ul { list-style: none; margin: .5rem 0 0; padding: 0; color: var(--ink); }

/* --- Task tables: selection column, Anl column, origin marker ------------ */
table.tasks th.sel, table.tasks td.sel { width: 1.6rem; text-align: center; padding-left: .3rem; padding-right: .3rem; }
table.tasks td.anl { text-align: center; white-space: nowrap; color: var(--muted); font-size: .78rem; }
table.tasks td.anl .clip { color: var(--ink-soft); }
.origin-mail { color: var(--muted); font-size: .8rem; margin-left: .2rem; }

/* Sortable headers (table_sort_controller.js sets sorted-asc / sorted-desc). */
th[data-sort-key] { cursor: pointer; user-select: none; }
th[data-sort-key]:hover { color: var(--accent); }
th.sorted-asc::after { content: " \25B2"; font-size: .7em; }
th.sorted-desc::after { content: " \25BC"; font-size: .7em; }
tr.has-menu { cursor: context-menu; }

/* Right-click context menu (context_menu_controller.js). */
.ctx-menu {
    position: absolute; z-index: 60; min-width: 220px;
    background: var(--card-raised); border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-raised); padding: .3rem;
    display: flex; flex-direction: column;
}
.ctx-menu .ctx-title {
    font-size: .72rem; font-weight: 650; color: var(--muted); padding: .3rem .6rem .4rem;
    border-bottom: 1px solid var(--line); margin-bottom: .2rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px;
}
.ctx-menu form { display: contents; }
.ctx-menu .ctx-item {
    display: block; width: 100%; text-align: left; font: inherit; font-size: .88rem; font-weight: 500;
    background: transparent; border: none; color: var(--ink); padding: .4rem .6rem; border-radius: 5px; cursor: pointer;
}
.ctx-menu .ctx-item:hover { background: var(--accent-soft); color: var(--accent-strong); text-decoration: none; transform: none; }
.ctx-menu .ctx-item.danger { color: var(--crit); }
.ctx-menu .ctx-prio { display: flex; gap: .5rem; align-items: center; padding: .3rem .6rem; font-size: .85rem; color: var(--ink-soft); }
.ctx-menu .ctx-prio select { padding: .1rem .3rem; font-size: .85rem; }

/* Hover preview (task_preview_controller.js). */
.task-preview {
    position: absolute; z-index: 50; max-width: 420px; pointer-events: none;
    background: var(--card-raised); border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-raised); padding: .6rem .8rem; font-size: .85rem;
}
.task-preview .tp-title { font-weight: 650; margin-bottom: .15rem; }
.task-preview .tp-meta { color: var(--muted); font-size: .75rem; margin-bottom: .4rem; }
.task-preview .tp-text { white-space: pre-wrap; color: var(--ink-soft); max-height: 220px; overflow: hidden; }

/* Rich-text editor (rich_text_controller.js). */
.rt-toolbar { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .3rem; }
.rt-toolbar button { padding: .2rem .5rem; font-size: .8rem; font-weight: 600; }
.rt-editor {
    min-height: 10rem; padding: .6rem .75rem; background: var(--card); color: var(--ink);
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow-y: auto;
}
.rt-editor:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.rt-editor p { margin: 0 0 .5rem; }
.rt-source { display: none; }

/* Stored rich text on the task page and in previews. */
.rich-text p { margin: 0 0 .6rem; }
.rich-text blockquote { border-left: 3px solid var(--line-strong); margin: .5rem 0; padding: .2rem .8rem; color: var(--muted); }
.rich-text pre { background: var(--accent-soft); padding: .5rem .7rem; border-radius: var(--radius-sm); overflow-x: auto; }
.rich-text table { width: auto; box-shadow: none; }

/* People picker (people_picker_controller.js). */
.picker-tools { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin: .3rem 0; font-size: .8rem; }
.picker-tools button { padding: .15rem .55rem; font-size: .78rem; }
.picker-tools select { padding: .15rem .4rem; font-size: .8rem; }
.picker-tools .count { color: var(--muted); margin-left: auto; }
