/* ============================================================================
   MailFlow prototype – stylesheet
   Keywords: tokens, palette, light theme, dark theme, sidebar, card, button,
             chips, labels, calendar, canvas, flow nodes, dialog, toast, help,
             mobile, phone, tablet, responsive, tab bar, drawer, icon rail, bottom sheet, safe area
   Calm "nature" look for a photography studio: sand neutrals, moss green as
   accent, terracotta as emphasis. Every colour is a token; components never
   use a hex value, so both themes stay correct.
   ========================================================================= */

:root {
    --accent: #3E6B4F;
    --accent-hover: #33593F;
    --accent-soft: #E3ECE1;
    --accent-text: #FFFFFF;
    --emphasis: #B8693D;
    --emphasis-soft: #F6E6DA;
    --on-emphasis: #FFFFFF;
    --ok: #4F8A5B;
    --warn: #B7862E;
    --danger: #A8473B;

    --bg: #F4F1EA;
    --sidebar: #EBE6DB;
    --panel: #FFFFFF;
    --panel-alt: #F8F6F1;
    --input: #FFFFFF;
    --border: #E2DBCD;
    --border-strong: #CBC1AE;
    --text: #25302A;
    --text-dim: #6B7169;
    --canvas: #F1EDE4;
    --canvas-dot: #D8D0BF;
    --edge: #9AA597;
    --hover: rgba(62, 107, 79, .07);

    /* Label colours: named, so a label stores a name and both themes resolve it */
    --lc-sage: #5E8C6A;
    --lc-clay: #B8693D;
    --lc-rose: #B85C7A;
    --lc-sky: #4E7FA3;
    --lc-sand: #A88A45;
    --lc-plum: #7D5C9E;
    --lc-slate: #5C6B73;
    --lc-moss: #6F7F3A;

    /* Node type colours on the flow canvas */
    --nc-trigger: var(--emphasis);
    --nc-logic: #7D5C9E;
    --nc-wait: #A88A45;
    --nc-mail: var(--accent);
    --nc-task: #4E7FA3;
    --nc-other: #5C6B73;

    --font: "Inter", "Segoe UI", system-ui, sans-serif;
    --display: "Fraunces", Georgia, "Times New Roman", serif;
    --radius: 10px;
    --radius-s: 7px;
    --shadow: 0 1px 2px rgba(37, 48, 42, .06), 0 2px 8px rgba(37, 48, 42, .05);
    --shadow-l: 0 12px 40px rgba(20, 28, 22, .22);
}

:root[data-theme="dark"] {
    --accent: #7FB08D;
    --accent-hover: #93C09F;
    --accent-soft: #26372B;
    --accent-text: #0F1A13;
    --emphasis: #D98C5F;
    --emphasis-soft: #3A2A20;
    --on-emphasis: #1A120C;
    --ok: #7FB08D;
    --warn: #D9AE5B;
    --danger: #E07B6D;

    --bg: #161A17;
    --sidebar: #1B201C;
    --panel: #20261F;
    --panel-alt: #1C211D;
    --input: #171B18;
    --border: #313A32;
    --border-strong: #46514A;
    --text: #DCE2DA;
    --text-dim: #949D93;
    --canvas: #181D19;
    --canvas-dot: #2C342D;
    --edge: #5E6A60;
    --hover: rgba(255, 255, 255, .05);

    --lc-sage: #86B792;
    --lc-clay: #DB936A;
    --lc-rose: #D98AA4;
    --lc-sky: #82AED0;
    --lc-sand: #D0B26E;
    --lc-plum: #AE8FD0;
    --lc-slate: #99A8B0;
    --lc-moss: #A9B86C;

    --nc-logic: #AE8FD0;
    --nc-wait: #D0B26E;
    --nc-task: #82AED0;
    --nc-other: #99A8B0;

    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --shadow-l: 0 12px 40px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body {
    margin: 0; height: 100%;
    overflow: hidden;                 /* the page never scrolls, the panels do */
    font: 14px/1.45 var(--font);
    background: var(--bg); color: var(--text);
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; letter-spacing: -.2px; }
.icon { flex: none; vertical-align: -.15em; }
.dim { color: var(--text-dim); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* --- Shell --------------------------------------------------------------- */

.app {
    display: grid; height: 100%;
    grid-template-columns: 236px 1fr;
    grid-template-rows: 1fr 26px;
}

.sidebar {
    display: flex; flex-direction: column; gap: 14px;
    min-height: 0; padding: 16px 12px 12px;
    background: var(--sidebar); border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand__mark { width: 34px; height: 34px; border-radius: 9px; }
.brand__name { font-family: var(--display); font-size: 19px; font-weight: 600; line-height: 1.1; }
.brand__sub { font-size: 11px; color: var(--text-dim); }

.workspace {
    display: flex; align-items: center; gap: 9px; width: 100%;
    padding: 8px 10px; text-align: left; cursor: pointer;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.workspace:hover { border-color: var(--border-strong); }
.workspace__avatar {
    display: grid; place-items: center; flex: none;
    width: 28px; height: 28px; border-radius: 8px;
    background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px;
}
.workspace__text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.workspace__label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }
.workspace__name { font-weight: 600; line-height: 1.25; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; }
.nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: var(--radius-s);
    color: var(--text-dim); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: var(--panel); color: var(--accent); box-shadow: var(--shadow); }
.nav__count {
    margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 10px;
    background: var(--emphasis); color: var(--on-emphasis); font-size: 11px; font-weight: 600; text-align: center;
}
.nav__sep { height: 1px; margin: 8px 6px; background: var(--border); }

.sidebar__foot { display: flex; gap: 6px; padding: 0 2px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
    display: flex; align-items: center; gap: 12px; flex: none;
    height: 64px; padding: 0 28px;
    border-bottom: 1px solid var(--border);
}
.topbar__title { font-size: 24px; }
.topbar__actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.view { flex: 1; min-height: 0; overflow-y: auto; padding: 24px 28px 32px; }
.view.workbench { padding: 0; overflow: hidden; display: grid; }

.statusbar {
    grid-column: 1 / -1;
    display: flex; align-items: center; gap: 10px; padding: 0 14px;
    background: var(--sidebar); border-top: 1px solid var(--border);
    font-size: 11.5px; color: var(--text-dim);
}
.statusbar__spacer { flex: 1; }
.statusbar__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.statusbar__dot.saving { background: var(--emphasis); }
.statusbar__dot.error { background: var(--danger); }
.statusbar__version { padding-left: 10px; border-left: 1px solid var(--border); }

/* --- Buttons ------------------------------------------------------------- */

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 13px; white-space: nowrap; cursor: pointer;
    background: var(--panel); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--radius-s);
    font-weight: 500;
}
.btn:hover { border-color: var(--accent); background: var(--hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--hover); border-color: transparent; }
.btn--danger { color: var(--danger); }
.btn--danger:hover { border-color: var(--danger); }
.btn--sm { padding: 4px 9px; font-size: 12.5px; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 32px; height: 32px; padding: 0; cursor: pointer;
    background: transparent; color: var(--text-dim);
    border: 1px solid transparent; border-radius: var(--radius-s);
}
.icon-btn:hover { background: var(--hover); color: var(--text); border-color: var(--border); }
.icon-btn--sm { width: 26px; height: 26px; }

/* --- Form fields --------------------------------------------------------- */

input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea {
    width: 100%; padding: 7px 10px;
    background: var(--input); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--radius-s);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

.field > label, .label {
    display: block; margin-bottom: 4px;
    font-size: 12px; font-weight: 500; color: var(--text-dim);
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

input[type="checkbox"] {
    appearance: none; -webkit-appearance: none; position: relative; flex: none;
    width: 17px; height: 17px; margin: 0; cursor: pointer;
    background: var(--input); border: 1.5px solid var(--border-strong); border-radius: 5px;
}
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after {
    content: ""; position: absolute; left: 4.5px; top: 1.5px; width: 4px; height: 8px;
    border: solid var(--accent-text); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
input[type="radio"] { accent-color: var(--accent); margin: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }

.toggle { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle__track {
    width: 34px; height: 20px; border-radius: 10px; flex: none;
    background: var(--border-strong); position: relative; transition: background .15s;
}
.toggle__track::after {
    content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px;
    border-radius: 50%; background: var(--panel); transition: transform .15s;
}
.toggle input:checked + .toggle__track { background: var(--ok); }
.toggle input:checked + .toggle__track::after { transform: translateX(14px); }

.search { position: relative; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-dim); }
.search input { padding-left: 32px !important; }

/* --- Cards and panels ---------------------------------------------------- */

.card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    min-width: 0;
}
.card__head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; }
.card__title { font-family: var(--display); font-size: 17px; font-weight: 600; }
.card__body { padding: 0 16px 16px; }
.card__body--flush { padding: 0 0 6px; }

.section-title {
    margin: 0 0 8px; font-size: 11.5px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim);
}

.panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel-alt); border-right: 1px solid var(--border); }
.panel:last-child { border-right: none; }
.panel--main { background: var(--bg); }
.panel__head { display: flex; align-items: center; gap: 8px; flex: none; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.panel__body { flex: 1; min-height: 0; overflow-y: auto; }
.panel__section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel__section:last-child { border-bottom: none; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.hstack { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* --- Rows ---------------------------------------------------------------- */

.row {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; cursor: pointer;
    border-top: 1px solid var(--border);
}
.row:first-child { border-top: none; }
.row:hover { background: var(--hover); }
.row.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.row__main { flex: 1; min-width: 0; }
.row__title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__meta { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__side { flex: none; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 4px 6px; max-width: 48%; }
@keyframes arrived { from { background: var(--emphasis-soft); } to { background: transparent; } }
.row.new { animation: arrived 1.6s ease-out; }

.avatar {
    display: grid; place-items: center; flex: none;
    width: 34px; height: 34px; border-radius: 50%;
    background: color-mix(in srgb, var(--c, var(--accent)) 18%, transparent);
    color: var(--c, var(--accent)); font-weight: 600; font-size: 12.5px;
}
.avatar--l { width: 52px; height: 52px; font-size: 18px; }

.datebox {
    flex: none; width: 44px; text-align: center; line-height: 1.1;
    padding: 5px 0; border-radius: var(--radius-s);
    background: var(--panel-alt); border: 1px solid var(--border);
}
.datebox__day { font-size: 16px; font-weight: 600; font-family: var(--display); }
.datebox__mon { font-size: 10.5px; text-transform: uppercase; color: var(--text-dim); letter-spacing: .4px; }
.datebox.today { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.datebox.today .datebox__mon { color: inherit; opacity: .8; }

/* --- Chips and badges ---------------------------------------------------- */

.chip {
    --c: var(--lc-slate);
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: 20px; white-space: nowrap;
    font-size: 12px; font-weight: 500; line-height: 1.5;
    background: color-mix(in srgb, var(--c) 16%, transparent);
    color: color-mix(in srgb, var(--c) 78%, var(--text));
    border: 1px solid transparent;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
button.chip { cursor: pointer; font-family: inherit; }
.chip--off { background: transparent; color: var(--text-dim); border-color: var(--border); }
.chip--off::before { background: var(--border-strong); }
button.chip--off:hover { border-color: var(--c); color: var(--text); }
.chip--plain::before { display: none; }

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 1px 8px; border-radius: 10px; white-space: nowrap;
    font-size: 11px; font-weight: 600;
    background: var(--panel-alt); color: var(--text-dim); border: 1px solid var(--border);
}
.badge--ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: transparent; }
.badge--warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: transparent; }
.badge--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: transparent; }
.badge--accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.badge--emphasis { background: var(--emphasis); border-color: var(--emphasis); color: var(--on-emphasis); }

.filterbar { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Stats --------------------------------------------------------------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { padding: 14px 16px; display: flex; gap: 12px; align-items: center; }
.stat__icon {
    display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; flex: none;
    background: var(--accent-soft); color: var(--accent);
}
.stat__value { font-family: var(--display); font-size: 24px; font-weight: 600; line-height: 1.1; }
.stat__label { font-size: 12.5px; color: var(--text-dim); }

.hero { margin-bottom: 18px; }
.hero h2 { font-size: 28px; }
.hero p { margin: 4px 0 0; color: var(--text-dim); }

.empty { padding: 26px 16px; text-align: center; color: var(--text-dim); }
.empty .icon { display: block; margin: 0 auto 8px; opacity: .6; }

/* --- Timeline ------------------------------------------------------------ */

.timeline { position: relative; padding: 4px 0; }
.tl-item { position: relative; display: flex; gap: 12px; padding: 8px 16px 8px 44px; cursor: default; }
.tl-item[data-mail] { cursor: pointer; }
.tl-item[data-mail]:hover { background: var(--hover); }
.tl-item::before { content: ""; position: absolute; left: 25px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.tl-item:first-child::before { top: 18px; }
.tl-item:last-child::before { bottom: calc(100% - 18px); }
.tl-dot {
    position: absolute; left: 18px; top: 10px; width: 16px; height: 16px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--panel); border: 2px solid var(--edge); color: var(--edge);
}
.tl-item.done .tl-dot { border-color: var(--ok); background: var(--ok); color: var(--panel); }
.tl-item.planned .tl-dot { border-color: var(--accent); }
.tl-item.skipped .tl-dot { border-style: dashed; }
.tl-item.skipped .tl-title { text-decoration: line-through; color: var(--text-dim); }
.tl-main { flex: 1; min-width: 0; }
.tl-title { font-weight: 500; }
.tl-meta { font-size: 12.5px; color: var(--text-dim); }
.tl-now {
    margin: 4px 16px 4px 44px; padding: 2px 0; font-size: 11px; font-weight: 600; letter-spacing: .5px;
    text-transform: uppercase; color: var(--emphasis); border-bottom: 1px dashed var(--emphasis);
}

/* --- Agenda -------------------------------------------------------------- */

.agenda { grid-template-columns: 1fr 330px; }
.cal { display: flex; flex-direction: column; min-height: 0; padding: 18px 22px 22px; }
.cal__head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal__month { font-family: var(--display); font-size: 22px; font-weight: 600; min-width: 210px; text-transform: capitalize; }
.cal__grid {
    flex: 1; min-height: 0; display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: auto;
    grid-auto-rows: minmax(0, 1fr);
    background: var(--border); gap: 1px;
    border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.cal__dow { padding: 8px 10px; background: var(--panel-alt); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }
.cal__day { position: relative; display: flex; flex-direction: column; gap: 3px; padding: 6px; min-height: 0; overflow: hidden; background: var(--panel); cursor: pointer; }
.cal__day:hover { background: var(--panel-alt); }
.cal__day.other { background: var(--panel-alt); }
.cal__day.other .cal__num { opacity: .45; }
.cal__num { font-size: 12.5px; font-weight: 600; color: var(--text-dim); width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.cal__day.today .cal__num { background: var(--accent); color: var(--accent-text); }
.cal__event {
    --c: var(--lc-slate);
    display: block; padding: 2px 7px; border-radius: 5px; cursor: pointer;
    font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    background: color-mix(in srgb, var(--c) 17%, var(--panel));
    color: color-mix(in srgb, var(--c) 70%, var(--text));
    border-left: 3px solid var(--c);
}
.cal__event:hover { background: color-mix(in srgb, var(--c) 27%, var(--panel)); }
.cal__event.cancelled { text-decoration: line-through; opacity: .6; }
.cal__more { font-size: 11.5px; color: var(--text-dim); padding-left: 4px; }

/* --- Contacts ------------------------------------------------------------ */

.contacts { grid-template-columns: 400px 1fr; }
.contact-head { display: flex; align-items: center; gap: 14px; padding: 20px 24px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.contact-head h2 { font-size: 24px; }
.contact-body { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; padding: 20px 24px 28px; align-items: start; }

/* --- Templates ----------------------------------------------------------- */

.templates { grid-template-columns: 290px minmax(0, 1fr) minmax(0, 1fr); }
.editor { padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.editor textarea { min-height: 340px; }
.mailframe { margin: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); overflow: hidden; box-shadow: var(--shadow); }
.mailframe__meta { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.mailframe__meta div { display: flex; gap: 8px; }
.mailframe__meta span:first-child { min-width: 64px; color: var(--text-dim); flex: none; }
.mailframe iframe { display: block; width: 100%; height: 560px; border: 0; background: #FFFFFF; }

/* --- Import -------------------------------------------------------------- */

.steps { display: flex; gap: 8px; margin-bottom: 18px; }
.step { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; border-radius: 20px; background: var(--panel); border: 1px solid var(--border); color: var(--text-dim); font-weight: 500; }
.step__n { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--panel-alt); font-size: 12px; font-weight: 600; }
.step.active { color: var(--text); border-color: var(--accent); }
.step.active .step__n, .step.done .step__n { background: var(--accent); color: var(--accent-text); }
.sources { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.source { padding: 18px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; text-align: left; font: inherit; color: inherit; }
.source:hover { border-color: var(--accent); }
.source[disabled] { cursor: default; opacity: .7; }
.source[disabled]:hover { border-color: var(--border); }
.source__icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.source__title { font-weight: 600; }
.dropzone {
    margin-top: 18px; padding: 34px; text-align: center; color: var(--text-dim);
    border: 2px dashed var(--border-strong); border-radius: var(--radius); cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 8px 12px; text-align: left; border-top: 1px solid var(--border); vertical-align: middle; }
table.grid th { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); border-top: none; background: var(--panel-alt); }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover { background: var(--hover); }
table.grid select { min-width: 190px; }
.sample { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }

/* --- Settings ------------------------------------------------------------ */

.settings { grid-template-columns: 230px 1fr; }
.subnav { padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.subnav a { padding: 8px 12px; border-radius: var(--radius-s); color: var(--text-dim); text-decoration: none; font-weight: 500; display: flex; align-items: center; gap: 9px; }
.subnav a:hover { background: var(--hover); color: var(--text); }
.subnav a.active { background: var(--panel); color: var(--accent); box-shadow: var(--shadow); }
.settings__content { padding: 22px 28px 32px; overflow-y: auto; min-height: 0; }
.settings__content > .card { max-width: 820px; margin-bottom: 18px; }
.swatches { display: flex; gap: 5px; }
.swatch { width: 20px; height: 20px; border-radius: 50%; background: var(--c); border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--text); }
.integrations { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.integration { padding: 16px; display: flex; flex-direction: column; gap: 8px; }

/* --- Flow editor --------------------------------------------------------- */

.floweditor { grid-template-columns: 250px minmax(0, 1fr) 340px; }
.palette { display: flex; flex-direction: column; gap: 6px; }
.palette__item {
    display: flex; align-items: center; gap: 9px; padding: 7px 10px; cursor: grab;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-s);
    font-weight: 500; user-select: none;
}
.palette__item:hover { border-color: var(--nc, var(--accent)); }
.palette__item .icon { color: var(--nc, var(--accent)); }

.canvas {
    position: relative; overflow: hidden; min-height: 0; outline: none; cursor: grab;
    background-color: var(--canvas);
    background-image: radial-gradient(var(--canvas-dot) 1.2px, transparent 1.2px);
    background-size: 22px 22px;
}
.canvas.panning { cursor: grabbing; }
.canvas__world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.canvas__edges { position: absolute; left: 0; top: 0; width: 10px; height: 10px; overflow: visible; }
.canvas__edges path { fill: none; }
.edge { stroke: var(--edge); stroke-width: 2; pointer-events: none; }
.edge-hit { stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.edge.selected { stroke: var(--emphasis); stroke-width: 3; }
.edge.sim { stroke: var(--accent); stroke-width: 3; }
.edge.temp { stroke: var(--accent); stroke-dasharray: 5 4; }
.canvas__tools { position: absolute; left: 14px; top: 14px; display: flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-s); box-shadow: var(--shadow); }

.node {
    --nc: var(--nc-other);
    position: absolute; width: 220px; cursor: move; user-select: none;
    background: var(--panel); border: 1px solid var(--border-strong); border-radius: 12px;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--nc);
}
.node:hover { border-color: var(--nc); border-top-color: var(--nc); }
.node.selected { box-shadow: 0 0 0 3px color-mix(in srgb, var(--nc) 35%, transparent), var(--shadow); border-color: var(--nc); }
.node.dim { opacity: .38; }
.node__head { display: flex; align-items: center; gap: 7px; padding: 8px 11px 2px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--nc); }
.node__title { padding: 0 11px; font-weight: 600; font-size: 13.5px; line-height: 1.3; }
.node__sum { padding: 2px 11px 12px; font-size: 12.5px; color: var(--text-dim); line-height: 1.35; }
.node__sim {
    position: absolute; right: -10px; top: -12px; min-width: 22px; height: 22px; padding: 0 6px;
    display: grid; place-items: center; border-radius: 11px;
    background: var(--accent); color: var(--accent-text); font-size: 11.5px; font-weight: 600;
}
.node__sim.skip { background: var(--panel); color: var(--text-dim); border: 1px dashed var(--border-strong); }
.port {
    position: absolute; width: 14px; height: 14px; border-radius: 50%;
    background: var(--panel); border: 2px solid var(--edge);
}
.port--in { top: -9px; left: 50%; transform: translateX(-50%); pointer-events: none; }
.port--out { bottom: -8px; transform: translateX(-50%); cursor: crosshair; }
.port--out:hover { border-color: var(--accent); background: var(--accent); }
.port__label {
    position: absolute; top: 15px; left: 50%; transform: translateX(-50%);
    padding: 0 7px; border-radius: 8px; white-space: nowrap;
    background: var(--panel); border: 1px solid var(--border); font-size: 11px; font-weight: 500; color: var(--text-dim);
    pointer-events: none;
}
.node--trigger { --nc: var(--nc-trigger); }
.node--switch, .node--condition { --nc: var(--nc-logic); }
.node--wait { --nc: var(--nc-wait); }
.node--mail { --nc: var(--nc-mail); }
.node--task { --nc: var(--nc-task); }

.sim-list { display: flex; flex-direction: column; }
.sim-step { display: grid; grid-template-columns: 24px 1fr; gap: 8px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 13px; cursor: pointer; }
.sim-step:first-child { border-top: none; }
.sim-step__n { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600; }
.sim-step.skip .sim-step__n { background: transparent; border: 1px dashed var(--border-strong); color: var(--text-dim); }
.sim-step.skip .sim-step__t { text-decoration: line-through; color: var(--text-dim); }

.variants { display: flex; flex-direction: column; gap: 8px; }
.variant { display: grid; grid-template-columns: 120px 1fr; gap: 8px; align-items: center; }

/* --- Dialog, menu, toast, help ------------------------------------------ */

.overlay {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center; padding: 16px;
    background: rgba(18, 24, 20, .45);
    animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.overlay--help { z-index: 200; }                    /* help stays above an open dialog */
.dialog {
    width: min(640px, 100%); max-height: 90vh; display: flex; flex-direction: column;
    background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
    box-shadow: var(--shadow-l);
    animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: .6; } to { transform: none; opacity: 1; } }
.dialog--wide { width: min(980px, 100%); }
.dialog__head { display: flex; align-items: center; gap: 10px; padding: 16px 20px 12px; }
.dialog__title { font-family: var(--display); font-size: 20px; font-weight: 600; flex: 1; }
.dialog__body { padding: 4px 20px 18px; overflow-y: auto; }
.dialog__foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }

.menu {
    position: fixed; z-index: 150; min-width: 230px; padding: 6px;
    background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-l);
}
.menu__title { padding: 6px 10px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }
.menu__item { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 10px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; text-align: left; }
.menu__item:hover { background: var(--hover); }
.menu__sep { height: 1px; margin: 5px 4px; background: var(--border); }
.menu-catcher { position: fixed; inset: 0; z-index: 140; }

.toasts { position: fixed; right: 18px; bottom: 40px; z-index: 250; display: flex; flex-direction: column; gap: 8px; }
.toast {
    max-width: 380px; padding: 11px 14px; display: flex; gap: 10px; align-items: flex-start;
    background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent);
    border-radius: var(--radius-s); box-shadow: var(--shadow-l);
    animation: toast-in .18s ease-out;
}
.toast .icon { color: var(--accent); margin-top: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.help { display: grid; grid-template-columns: 220px 1fr; min-height: 0; flex: 1; }
.help__nav { border-right: 1px solid var(--border); padding: 0 8px 12px 0; overflow-y: auto; }
.help__nav a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--text-dim); text-decoration: none; }
.help__nav a:hover { background: var(--hover); color: var(--text); }
.help__nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.help__doc { padding: 0 4px 12px 22px; overflow-y: auto; line-height: 1.6; }
.help__doc h1 { font-size: 22px; margin-bottom: 6px; }
.help__doc h2 { font-size: 16px; margin: 20px 0 6px; }
.help__doc table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.help__doc th, .help__doc td { text-align: left; padding: 6px 9px; border-top: 1px solid var(--border); vertical-align: top; }
.help__doc th { background: var(--panel-alt); font-weight: 600; }
.help__doc code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; padding: 1px 5px; border-radius: 4px; background: var(--panel-alt); border: 1px solid var(--border); }
.help__doc mark { background: var(--emphasis-soft); color: inherit; }
kbd { font-family: inherit; font-size: 11.5px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border-strong); border-bottom-width: 2px; background: var(--panel-alt); }

@media (max-width: 1320px) {
    .floweditor { grid-template-columns: 210px minmax(0, 1fr) 300px; }
    .templates { grid-template-columns: 250px minmax(0, 1fr) minmax(0, 1fr); }
    .contacts { grid-template-columns: 340px 1fr; }
    .contact-body { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* --- Customer status, facts, static rows ---------------------------------- */

.badge--status { color: var(--lc-plum); border-color: color-mix(in srgb, var(--lc-plum) 45%, transparent); background: color-mix(in srgb, var(--lc-plum) 10%, transparent); }
.badge--vip { background: var(--emphasis); border-color: var(--emphasis); color: var(--on-emphasis); }
.contact-head h2 .badge { vertical-align: 4px; font-family: var(--font); }
.chip .icon { margin-left: -2px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px 16px; }
.facts div { display: flex; flex-direction: column; gap: 2px; }
.facts > div > span { font-size: 12px; color: var(--text-dim); }
.facts strong { font-weight: 600; }
.row--static { cursor: default; }
.row--static:hover { background: transparent; }
.source__icon--danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.loc-info { margin-top: 6px; font-size: 12.5px; color: var(--text-dim); line-height: 1.5; }
.loc-info:empty { display: none; }

/* --- Campaigns ------------------------------------------------------------- */

.campaigns { grid-template-columns: 290px minmax(0, 1fr) 380px; }
.campaigns .editor .card { max-width: 760px; }
.tabs { display: flex; flex: none; border-bottom: 1px solid var(--border); }
.tabs button {
    flex: 1; padding: 10px 8px; cursor: pointer; font-weight: 500; color: var(--text-dim);
    background: transparent; border: 0; border-bottom: 2px solid transparent;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* --- Tracking results ------------------------------------------------------ */

.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.result {
    display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 0 8px; align-items: center;
    padding: 9px 11px; text-align: left; cursor: pointer;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-s);
}
.result .icon { color: var(--text-dim); }
.result:hover { border-color: var(--accent); }
.result.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.result.active .icon { color: var(--accent); }
.result__n { font-family: var(--display); font-size: 20px; font-weight: 600; line-height: 1.1; }
.result__l { grid-column: 1 / -1; font-size: 12px; color: var(--text-dim); }
.result__p { grid-column: 1 / -1; font-size: 11.5px; color: var(--text-dim); }
.result__p:empty { display: none; }
[data-results] table.grid { font-size: 13px; }
[data-results] table.grid tbody tr { cursor: pointer; }

/* --- House style, designs, media -------------------------------------------- */

.brand-edit { display: grid; grid-template-columns: 200px 1fr; gap: 20px; align-items: start; }
.logo-box {
    display: grid; place-items: center; height: 120px; padding: 12px;
    border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--panel-alt);
}
.logo-box img { max-width: 100%; max-height: 96px; }
.colors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; }
.colorfield { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.colorfield input[type="color"] { width: 34px; height: 34px; padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: none; cursor: pointer; }
.colorfield code { color: var(--text-dim); }
.designs { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.design { padding: 0; cursor: pointer; text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font: inherit; color: inherit; }
.design:hover { border-color: var(--accent); }
.design.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.design__frame { height: 240px; overflow: hidden; position: relative; background: #FFFFFF; pointer-events: none; }
.design__frame iframe { position: absolute; left: 0; top: 0; width: 600px; height: 860px; border: 0; transform: scale(.29); transform-origin: 0 0; }
.design__name { display: flex; align-items: center; gap: 6px; padding: 8px 12px; font-weight: 500; border-top: 1px solid var(--border); }
.design.active .design__name { color: var(--accent); }
.media-thumb { width: 64px; height: 36px; object-fit: cover; border-radius: 5px; flex: none; }

/* Media playback page: shown in the studio's colours, like the recipient will see it. */
.mediapage {
    display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 28px 18px;
    border-radius: var(--radius); background: var(--b-bg); color: var(--b-text);
}
.mediapage__brand { font: 600 22px/1.2 var(--display); color: var(--b-primary); }
.mediapage__brand img { max-height: 64px; }
.mediapage__title { font-weight: 600; }
.mediapage video { width: 100%; max-height: 52vh; border-radius: 8px; background: #000; }
.mediapage audio { width: min(380px, 100%); }
.mediapage .empty { color: inherit; opacity: .7; }

.recorder { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 8px 0; }
.recorder__btn {
    display: grid; place-items: center; width: 76px; height: 76px; border-radius: 50%; cursor: pointer;
    background: var(--accent); color: var(--accent-text); border: 0; box-shadow: var(--shadow);
}
.recorder__btn.recording { background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--danger) 20%, transparent); } }
.recorder__time { font-size: 22px; font-family: var(--display); }

@media (max-width: 1320px) {
    .campaigns { grid-template-columns: 240px minmax(0, 1fr) 320px; }
    .brand-edit { grid-template-columns: 1fr; }
}

/* ============================================================================
   Compact layout: phone and tablet portrait (<= 900px), extra for phones (<= 600px)
   The shell turns into: top bar with back arrow, tab bar at the bottom, sidebar as
   drawer behind "Meer". Workbench pages with a list and a detail (.md) show one of the
   two: the list without an id in the URL, the detail with one (.has-detail). Panels
   then stack and the whole view scrolls instead of every panel on its own.
   900px is the same breakpoint as AF.isMobile() in js/util.js.
   Between 901 and 1180px (tablet landscape, small laptop) the sidebar is an icon rail,
   so the three-column pages keep room for their middle column.
   ========================================================================= */

/* Desktop: the compact-only parts of the shell stay hidden. */
.tabbar, .drawer-backdrop, .topbar__back, .sidebar__version, .mobile-only { display: none; }
/* Output ports get a bigger invisible hit area, so a finger (or a hurried mouse) finds them. */
.port--out::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; }
.canvas { touch-action: none; }

/* --- Icon rail (901-1180px) ---------------------------------------------- */
@media (min-width: 901px) and (max-width: 1180px) {
    .app { grid-template-columns: 68px minmax(0, 1fr); }
    .sidebar { align-items: center; padding: 14px 8px 12px; }
    .brand { padding: 0; }
    .brand > div, .workspace__text, .workspace > .icon, .nav a > span:not(.nav__count) { display: none; }
    .workspace { width: auto; padding: 6px; }
    .nav { align-items: center; width: 100%; }
    .nav a { position: relative; justify-content: center; width: 44px; height: 40px; padding: 0; }
    .nav__count { position: absolute; top: 1px; right: -2px; min-width: 16px; padding: 0 4px; font-size: 10px; }
    .nav__sep { width: 32px; margin: 8px auto; }
    .sidebar__foot { flex-direction: column; }
}

/* --- Compact (<= 900px) ---------------------------------------------------- */
@media (max-width: 900px) {
    html, body { font-size: 15px; }
    .app {
        height: 100vh; height: 100dvh;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) auto;
    }
    .statusbar { display: none; }

    /* Drawer (the sidebar) */
    .sidebar {
        position: fixed; z-index: 120; left: 0; top: 0; bottom: 0; width: min(300px, 84vw);
        padding: calc(18px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
        border-right: 0; border-radius: 0 18px 18px 0;
        transform: translateX(-104%); transition: transform .24s cubic-bezier(.2, .8, .2, 1);
    }
    .app.drawer-open .sidebar { transform: none; box-shadow: var(--shadow-l); }
    .drawer-backdrop {
        display: block; position: fixed; inset: 0; z-index: 110;
        background: rgba(18, 24, 20, .45); opacity: 0; pointer-events: none; transition: opacity .2s;
    }
    .app.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
    .nav a { padding: 11px 12px; font-size: 15px; }
    .sidebar__foot { align-items: center; }
    .sidebar__foot .icon-btn { width: 40px; height: 40px; }
    .sidebar__version { display: block; margin-left: auto; padding-right: 6px; font-size: 11.5px; color: var(--text-dim); }

    /* Top bar */
    .topbar {
        height: auto; min-height: calc(56px + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 10px 0 16px; gap: 4px;
        background: var(--bg);
    }
    .topbar__title { flex: 1; min-width: 0; font-size: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .topbar__back.show { display: inline-grid; flex: none; width: 40px; height: 40px; margin-left: -10px; color: var(--text); }
    .topbar__actions { gap: 6px; }

    /* Tab bar */
    .tabbar {
        display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
        padding: 4px 4px env(safe-area-inset-bottom);
        background: var(--sidebar); border-top: 1px solid var(--border);
    }
    .tabbar a, .tabbar button {
        position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px;
        padding: 6px 0 7px; border: 0; background: none; cursor: pointer;
        color: var(--text-dim); text-decoration: none; font-size: 11px; font-weight: 500;
        -webkit-tap-highlight-color: transparent;
    }
    .tabbar .icon { box-sizing: content-box; padding: 3px 16px; border-radius: 14px; transition: background .15s; }
    .tabbar .active { color: var(--accent); font-weight: 600; }
    .tabbar .active .icon { background: var(--accent-soft); }
    .tabbar__count {
        position: absolute; top: 2px; left: calc(50% + 8px);
        min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
        background: var(--emphasis); color: var(--on-emphasis);
        font-size: 10.5px; font-weight: 600; line-height: 17px; text-align: center;
    }

    /* Touch sizes; 16px inputs, otherwise iOS zooms in on focus */
    input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea { font-size: 16px; padding: 9px 11px; }
    input[type="checkbox"] { width: 20px; height: 20px; }
    input[type="checkbox"]:checked::after { left: 6px; top: 2.5px; width: 5px; height: 9px; }
    .btn { padding: 9px 14px; }
    .btn--sm { padding: 6px 11px; }
    .icon-btn { width: 38px; height: 38px; }
    .icon-btn--sm { width: 32px; height: 32px; }
    .row { padding: 12px 16px; }
    .menu { max-width: calc(100vw - 16px); }
    .menu__item { padding: 11px 12px; }

    /* Page content */
    .view { padding: 16px 14px 28px; }
    .steps { overflow-x: auto; scrollbar-width: none; margin: 0 -14px 14px; padding: 0 14px; }
    .step { flex: none; }
    /* Wide tables scroll sideways inside their card instead of widening the page. */
    table.grid { display: block; overflow-x: auto; white-space: nowrap; }
    table.grid select { min-width: 160px; }
    .sample { max-width: 150px; }
    .toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }

    /* Workbenches: one column, the view scrolls */
    .view.workbench { display: block; overflow-y: auto; }
    .view.workbench > .panel { border-right: 0; }
    .view.workbench .panel__body { flex: none; overflow: visible; }
    .md:not(.has-detail) > :not(:first-child) { display: none; }
    .md.has-detail > :first-child { display: none; }
    .md.has-detail > .panel + .panel { border-top: 1px solid var(--border); }
    .md > .panel:first-child { min-height: 100%; background: var(--panel); }
    /* Desktop pre-selects the first item; in the compact list nothing is selected. */
    .md:not(.has-detail) .row.active { background: none; box-shadow: none; }
    /* List heads that only repeat the page title */
    .campaigns > .panel:first-child > .panel__head,
    .templates > .panel:first-child > .panel__head,
    .floweditor > .panel:first-child > .panel__head:first-child { display: none; }

    /* Contacts: sticky search, filters scroll sideways, rows without tag chips */
    .contacts > .panel:first-child > .panel__head:first-child { position: sticky; top: 0; z-index: 2; background: var(--panel); }
    .contacts .panel__head .filterbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
    .contacts .panel__head .chip { flex: none; }
    .contacts .row__side .chip { display: none; }
    .contact-head { padding: 16px 14px 14px; }
    .contact-body { grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 14px 12px 24px; }

    /* Editors (campaigns, templates) with the preview below */
    .editor { padding: 16px 12px; gap: 12px; }
    .editor textarea { min-height: 260px; }
    .campaigns .editor .card { max-width: none; }
    .mailframe { margin: 12px; }
    .mailframe iframe { height: 520px; }
    .tabs button { padding: 12px 6px; }

    /* Settings: the sections as a list, a section as detail */
    .settings .subnav { padding: 8px 0; gap: 0; }
    .settings .subnav a { padding: 14px 18px; font-size: 15px; color: var(--text); border-radius: 0; border-bottom: 1px solid var(--border); }
    .settings .subnav a.active { background: none; box-shadow: none; color: var(--text); }
    .settings .subnav a .icon { color: var(--accent); }
    .settings .subnav a::after { content: "\203A"; margin-left: auto; font-size: 20px; line-height: 1; color: var(--text-dim); }
    .settings__content { padding: 16px 12px 28px; overflow: visible; }
    .settings__content > .card { max-width: none; margin-bottom: 14px; }

    /* Agenda: tap a day for its shoots, listed below the month */
    .cal { padding: 12px 10px 16px; }
    .cal__head { gap: 4px; margin-bottom: 10px; }
    .cal__month { order: -1; flex: 1; min-width: 0; font-size: 20px; padding-left: 4px; }
    .cal__head > .grow, .cal__head > .hstack { display: none; }
    .cal__grid { grid-template-rows: auto !important; grid-auto-rows: 96px; }
    .cal__day.selected { background: var(--accent-soft); }
    .cal__day.selected .cal__num { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); }
    .cal__day.today.selected .cal__num { color: var(--accent-text); }
    .agenda > .panel { border-top: 1px solid var(--border); }

    /* Flow editor: list of flows; in a flow the canvas fills the screen and the
       properties are a bottom sheet (tap the handle, or select a block). */
    .floweditor .flows__palette { display: none; }
    .floweditor .flows__list { max-height: none !important; }
    .floweditor.has-detail { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); position: relative; overflow: hidden; }
    .floweditor .canvas__tools { left: 10px; top: 10px; }
    .canvas__tools .mobile-only { display: inline-flex; }
    .floweditor [data-props] {
        position: absolute; z-index: 30; left: 0; right: 0; bottom: 0; max-height: 74%;
        background: var(--panel); border: 1px solid var(--border); border-bottom: 0;
        border-radius: 18px 18px 0 0; box-shadow: 0 -10px 30px rgba(20, 28, 22, .18);
        transform: translateY(calc(100% - 58px)); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
    }
    .floweditor [data-props].sheet-open { transform: none; }
    .floweditor [data-props] > .panel__head:first-child { position: relative; padding-top: 20px; cursor: pointer; }
    .floweditor [data-props] > .panel__head:first-child::before {
        content: ""; position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; margin-left: -19px;
        border-radius: 2px; background: var(--border-strong);
    }
    .floweditor [data-props] .panel__body { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 8px; }
}

/* --- Phone (<= 600px) ------------------------------------------------------ */
@media (max-width: 600px) {
    /* Actions shrink to their icon; the label stays as title/aria-label (app.js). */
    .topbar__actions .btn { width: 40px; height: 40px; padding: 0; gap: 0; justify-content: center; font-size: 0; border-radius: 12px; }
    .topbar__actions .btn .icon { width: 19px; height: 19px; }

    .hero h2 { font-size: 23px; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
    .stat { padding: 12px; gap: 10px; }
    .stat__icon { width: 34px; height: 34px; }
    .stat__value { font-size: 21px; }
    .grid-2, .form-grid, .form-grid--3 { grid-template-columns: minmax(0, 1fr); }
    .form-grid .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stack, .grid-2 { gap: 14px; }
    .card__head { padding: 13px 14px 9px; }
    .card__body { padding: 0 14px 14px; }
    .integrations { grid-template-columns: minmax(0, 1fr); }
    .sources { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .source { padding: 14px; }
    .dropzone { padding: 26px 16px; }
    .toasts { left: 12px; right: 12px; }
    .toast { max-width: none; }

    /* Contact and campaign head: name next to the avatar, the actions on their own row */
    .contact-head { flex-wrap: wrap; gap: 12px; }
    .contact-head h2 { font-size: 21px; }
    .contact-head:has(> .btn) > .grow { flex: 1 1 calc(100% - 70px); }
    .contact-head > .btn { flex: 1; justify-content: center; }

    .editor .hstack > select { flex: 1 1 140px; }
    /* Campaign video/voice: badge and remove on one row, the position below */
    .editor .hstack:has(> [data-media-remove]) > select { order: 2; flex: 1 1 100%; }
    .editor [data-media-remove] { margin-left: auto; }

    .brand-edit { grid-template-columns: minmax(0, 1fr); }
    .colors { grid-template-columns: minmax(0, 1fr); }
    .colorfield input[type="color"] { flex: none; }
    .designs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .design__frame { height: 214px; }
    .design__frame iframe { transform: scale(.26); }
    .variant { grid-template-columns: 96px minmax(0, 1fr); }

    /* Agenda: a dot per shoot (names do not fit); the day list shows who */
    .cal__grid { grid-auto-rows: 52px; }
    .cal__dow { padding: 6px 0; text-align: center; font-size: 10.5px; }
    .cal__day {
        display: grid; grid-template-columns: repeat(3, 6px); justify-content: center; align-content: start;
        gap: 4px 3px; padding: 5px 2px;
    }
    .cal__num { grid-column: 1 / -1; justify-self: center; width: 28px; height: 28px; font-size: 13px; }
    .cal__event { width: 6px; height: 6px; padding: 0; border: 0; border-radius: 50%; font-size: 0; background: var(--c); pointer-events: none; }
    .cal__event.cancelled { opacity: .35; }
    .cal__more { display: none; }

    /* Dialogs become sheets from the bottom */
    .overlay { align-items: flex-end; padding: 0; }
    .dialog, .dialog--wide {
        width: 100%; max-height: calc(100dvh - 24px - env(safe-area-inset-top));
        border-radius: 18px 18px 0 0; border-bottom: 0;
        animation: sheet-up .24s cubic-bezier(.2, .8, .2, 1);
    }
    @keyframes sheet-up { from { transform: translateY(60px); opacity: .4; } to { transform: none; opacity: 1; } }
    .dialog__head { padding: 16px 16px 10px; }
    .dialog__title { font-size: 19px; }
    .dialog__body { padding: 4px 16px 16px; }
    .dialog__foot { flex-wrap: wrap; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
    /* The main action as a full-width button at the bottom, where the thumb is */
    .dialog__foot .btn--primary { flex: 1 1 100%; justify-content: center; padding: 12px 14px; }
    .overlay--help .dialog { height: calc(100dvh - 24px - env(safe-area-inset-top)) !important; }
    .dialog__head .search { width: 150px !important; }
    .help { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
    .help__nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 0 0 10px; border-right: 0; border-bottom: 1px solid var(--border); }
    .help__nav a { flex: none; white-space: nowrap; }
    .help__doc { padding: 12px 2px; }
}

/* ============================================================================
   Login pages: inloggen, wachtwoord-vergeten, wachtwoord-herstellen, uitnodiging
   Public pages with js/auth.js. Same tokens and components as the app (card,
   field, btn, brand), one centred card; on a phone it fills the width.
   ========================================================================= */

body.auth-page { overflow-y: auto; }
.auth {
    display: grid; place-items: center; min-height: 100%;
    padding: max(32px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
.auth__card { display: flex; flex-direction: column; gap: 18px; width: 100%; max-width: 400px; padding: 28px 28px 24px; }
.auth__brand { padding: 0; }
.auth__title { font-size: 24px; }
.auth__intro { margin: 0; color: var(--text-dim); }
.auth__intro strong { color: var(--text); }
.auth__hint { margin: -6px 0 0; font-size: 12px; color: var(--text-dim); }
.auth__form { display: flex; flex-direction: column; gap: 14px; }
.auth__form input[readonly] { background: var(--panel-alt); color: var(--text-dim); }
.auth__submit { justify-content: center; padding: 10px 14px; }
.auth__msg {
    margin: 0; padding: 9px 12px; font-size: 13px;
    color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, transparent);
    border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); border-radius: var(--radius-s);
}
.auth__msg--ok { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.auth__links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; }

@media (max-width: 600px) {
    .auth { place-items: start center; padding-top: max(20px, env(safe-area-inset-top)); }
    .auth__card { padding: 22px 18px 20px; }
    .auth__submit { padding: 12px 14px; }
}
