/* marketing-engine dashboard — single stylesheet, no external assets */

:root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --ink: #1c2330;
    --dim: #68738a;
    --line: #e2e6ee;
    --accent: #2456d6;
    --ok: #1d8a4a;
    --warn: #b97a10;
    --bad: #c22f2f;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
}

/* -- chrome -- */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    height: 56px;
    background: #16203a;
    color: #fff;
}
.brand { font-weight: 700; letter-spacing: .02em; }
.brand span { color: #7ea2ff; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
    color: #c6cfe4;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
}
.topbar nav a:hover { background: #24304f; color: #fff; }
.topbar nav a.on { background: #2c3b63; color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar .logout { color: #c6cfe4; font-size: 13px; text-decoration: none; }
.topbar .logout:hover { color: #fff; }

.pill {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    padding: 3px 9px;
    border-radius: 999px;
}
.pill-dry { background: #ffdf8e; color: #6b4d00; }
.pill-live { background: #ff5c5c; color: #fff; }

.killbanner {
    background: var(--bad);
    color: #fff;
    text-align: center;
    padding: 9px 16px;
    font-weight: 600;
    font-size: 14px;
}

main { max-width: 1100px; margin: 28px auto 60px; padding: 0 20px; }
.foot { text-align: center; color: var(--dim); font-size: 12px; padding: 24px 0 36px; }

/* -- building blocks -- */
h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 16px; margin: 26px 0 10px; }
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 18px 20px;
    margin-bottom: 20px;
}
.muted { color: var(--dim); font-size: 13px; }

table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th {
    text-align: left;
    color: var(--dim);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 8px 10px;
    border-bottom: 2px solid var(--line);
}
table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 999px;
    background: #eef1f7;
    color: var(--dim);
}
.badge.live { background: #def4e6; color: var(--ok); }
.badge.pending { background: #fdf1d8; color: var(--warn); }
.badge.paused { background: #eef1f7; color: var(--dim); }
.badge.killed { background: #fbdada; color: var(--bad); }
.badge.draft { background: #eef1f7; color: var(--dim); }
.badge.queued { background: #fdf1d8; color: var(--warn); }
.badge.published { background: #def4e6; color: var(--ok); }
.badge.active { background: #def4e6; color: var(--ok); }

button, .btn {
    font: inherit;
    font-size: 13px;
    padding: 6px 14px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    cursor: pointer;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); color: #fff; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.danger:hover { filter: brightness(1.08); color: #fff; }

/* -- kill switch -- */
.killswitch { text-align: center; padding: 26px 20px; }
.killswitch button.arm {
    font-size: 18px;
    font-weight: 700;
    padding: 16px 42px;
    border-radius: 12px;
    background: var(--bad);
    border: 3px solid #8f1f1f;
    color: #fff;
    letter-spacing: .04em;
}
.killswitch button.arm:hover { filter: brightness(1.1); }
.killswitch button.disarm {
    font-size: 16px;
    font-weight: 700;
    padding: 14px 36px;
    border-radius: 12px;
    background: var(--ok);
    border: 3px solid #135e33;
    color: #fff;
}
.killswitch .state { margin-top: 10px; font-weight: 700; }
.killswitch .state.armed { color: var(--bad); }

/* -- stat tiles -- */
.tiles { display: flex; gap: 14px; flex-wrap: wrap; }
.tile {
    flex: 1 1 150px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px 16px;
}
.tile .k { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.tile .v { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* -- creatives gallery -- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}
.card img { width: 100%; aspect-ratio: 1200 / 628; object-fit: cover; display: block; background: #dde2ec; }
.card .body { padding: 10px 14px 14px; }
.card .h { font-weight: 600; font-size: 14px; }
.card .t { color: var(--dim); font-size: 13px; margin-top: 4px; }

/* -- forms -- */
form.stack label { display: block; font-size: 13px; color: var(--dim); margin: 12px 0 4px; }
form.stack input[type=text], form.stack input[type=password], form.stack select, form.stack textarea {
    width: 100%;
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
}
form.stack textarea { min-height: 160px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
form.inline { display: inline; }

/* -- login -- */
.login-wrap { max-width: 360px; margin: 12vh auto 0; }
.login-wrap .panel { padding: 26px 28px; }
.login-wrap h1 { text-align: center; }

.flash { border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
.flash.ok { background: #def4e6; color: var(--ok); }
.flash.err { background: #fbdada; color: var(--bad); }

pre.log { font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all; margin: 0; }

/* -- article preview (content.php ?preview=) -- */
.article-preview { max-width: 720px; line-height: 1.65; font-size: 15px; }
.article-preview h2 { margin: 22px 0 8px; font-size: 20px; }
.article-preview h3 { margin: 16px 0 6px; font-size: 16px; }
.article-preview p { margin: 10px 0; }
.article-preview ul { margin: 10px 0 10px 22px; }
.article-preview li { margin: 6px 0; }

/* -- assistant (assistant.php) -- */
.assistant-answer { margin: 8px 0 14px; line-height: 1.6; }
details.assistant-tools { margin-top: 8px; }
details.assistant-tools summary {
    cursor: pointer;
    color: var(--dim);
    font-size: 13px;
    user-select: none;
}
details.assistant-tools[open] summary { margin-bottom: 8px; }
.toolcall {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    margin: 8px 0;
    background: #fafbfd;
}
.toolcall .badge { margin-right: 6px; }
.toolcall pre.log { margin-top: 6px; }

/* -- number inputs share the stack styling -- */
form.stack input[type=number] {
    width: 100%;
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
}

/* ======================================================================
   PHONE LAYER
   One breakpoint at 900px. The desktop topbar (brand + 7 nav links +
   mode pill + log out) has an intrinsic minimum around 842px, so 900 is
   the first width where the desktop chrome still holds together.
   Everything below it is treated as a phone: nav becomes a horizontal
   scroll strip, wide tables restack into label/value cards, controls
   grow to 44px, inputs go to 16px so iOS does not zoom on focus.

   Table restacking uses three generic cell hooks set in the markup:
     .cell-main    the row's headline (pulled to the top of the card)
     .cell-block   full-width prose or <pre> (keeps its DOM position)
     .cell-actions the row's buttons and links (pushed to the bottom)
   Every other cell carries data-label="..." and renders as a
   label/value row. The header <tr> is hidden because the labels move
   onto the cells.
   ====================================================================== */

@media (max-width: 900px) {

    body { -webkit-text-size-adjust: 100%; }

    /* -- topbar: brand + status on line 1, nav as a scroll strip on line 2 -- */
    .topbar {
        flex-wrap: wrap;
        align-items: stretch;
        height: auto;
        gap: 0;
        padding: 0;
    }
    .brand { display: flex; align-items: center; padding: 12px 14px; }
    .topbar-right { margin-left: auto; padding: 12px 14px; }
    .topbar .logout {
        display: flex;
        align-items: center;
        min-height: 44px;
        padding: 0 4px;
        font-size: 14px;
    }
    .topbar nav {
        order: 3;
        flex: 1 0 100%;
        min-width: 0;
        gap: 0;
        padding: 4px 8px;
        border-top: 1px solid #24304f;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .topbar nav::-webkit-scrollbar { display: none; }
    .topbar nav a {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        min-height: 44px;
        padding: 0 13px;
        white-space: nowrap;
    }

    .killbanner { text-align: left; }

    main { margin: 18px auto 40px; padding: 0 14px; }
    .panel { padding: 14px 14px; border-radius: 9px; }
    code, .muted, .article-preview { overflow-wrap: anywhere; }

    /* -- tappable controls -- */
    button, .btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 14px;
    }
    form.stack > button { width: 100%; }
    details.assistant-tools summary { padding: 12px 0; }

    /* -- forms: 16px keeps iOS from zooming the viewport on focus -- */
    form.stack input[type=text],
    form.stack input[type=password],
    form.stack input[type=number],
    form.stack select,
    form.stack textarea {
        font-size: 16px;
        padding: 11px 12px;
    }
    form.stack textarea { font-size: 16px; }
    form.stack label { margin-top: 14px; }

    .login-wrap { max-width: none; margin: 6vh 14px 0; }
    .login-wrap .panel { padding: 22px 18px; }

    /* -- kill switch fills the panel so it is impossible to miss -- */
    .killswitch { padding: 20px 14px; }
    .killswitch button.arm,
    .killswitch button.disarm { width: 100%; padding: 16px 18px; }

    /* -- one column for every card grid -- */
    .gallery { grid-template-columns: 1fr; gap: 14px; }
    .tiles { gap: 10px; }
    .tile { flex: 1 1 100%; }
    .card img { max-width: 100%; }

    /* -- tables restack into one card per row -- */
    table.grid,
    table.grid tbody,
    table.grid tr,
    table.grid td { display: block; width: 100%; }

    table.grid tr:first-child { display: none; }

    table.grid tr {
        display: flex;
        flex-direction: column;
        border: 1px solid var(--line);
        border-radius: 9px;
        padding: 12px;
        margin-bottom: 10px;
    }
    table.grid tr:last-child { margin-bottom: 0; }

    table.grid td {
        border: 0;
        padding: 5px 0;
        overflow-wrap: anywhere;
    }
    table.grid td:first-child { padding-top: 0; }
    table.grid td:last-child { padding-bottom: 0; }

    table.grid td[data-label] {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 12px;
        text-align: right;
        border-top: 1px solid var(--line);
    }
    table.grid td[data-label]::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--dim);
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: .05em;
        text-align: left;
    }

    table.grid td.cell-main {
        order: -1;
        display: block;
        text-align: left;
        padding-top: 0;
    }
    table.grid td.cell-block { display: block; text-align: left; }

    table.grid td.cell-actions {
        order: 99;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 12px;
    }
    table.grid td.cell-actions > * { flex: 1 1 130px; }
    table.grid td.cell-actions form.inline { display: block; }
    table.grid td.cell-actions button { width: 100%; }
    /* Links that act as controls become chips so they clear 44px.
       a.tap marks the ones that sit outside an actions cell. */
    table.grid td.cell-actions a,
    a.tap {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        padding: 10px 14px;
        border: 1px solid var(--line);
        border-radius: 7px;
        background: #fff;
        color: var(--accent);
        font-size: 14px;
        text-decoration: none;
    }
    a.tap { margin-top: 10px; }

    /* -- actions log: 200 rows, so it gets a tighter three-line entry
          (action + mode, then timestamp + actor, then the detail) instead
          of the generic one-row-per-field card. Column order is fixed by
          the page markup: when, actor, action, mode, detail. -- */
    table.grid.log tr:not(:first-child) {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 1px 10px;
        padding: 10px 12px;
    }
    table.grid.log td {
        display: block;
        border-top: 0;
        text-align: left;
        padding: 1px 0;
    }
    table.grid.log td::before { content: none; }
    table.grid.log td:nth-child(3) { grid-area: 1 / 1; }
    table.grid.log td:nth-child(4) { grid-area: 1 / 2; justify-self: end; }
    table.grid.log td:nth-child(1) { grid-area: 2 / 1; font-size: 12px; }
    table.grid.log td:nth-child(2) { grid-area: 2 / 2; justify-self: end; font-size: 12px; }
    table.grid.log td:nth-child(5) { grid-area: 3 / 1 / auto / -1; padding-top: 5px; }
    table.grid.log td.cell-block:first-child { grid-area: 1 / 1 / auto / -1; }
}
