:root {
    --bg: #b9cfe9;          /* pale blue work area */
    --panel: #eef3fb;
    --key: #a9cbf2;         /* blue keypad keys */
    --key-border: #2f64ad;
    --navy: #0b2e84;        /* key labels / headings */
    --green-1: #c4e28f; --green-2: #96c64f;
    --red-1: #f47a7a;   --red-2: #d51f1f;
    --orange: #f59a2e;
    --yellow: #fffbe0;      /* stripes + input fields */
    --grid-line: #9db6d8;
    --text: #12233f;
    --muted: #6b7c96;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 "Segoe UI", Tahoma, Arial, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 6px 12px; background: linear-gradient(#ffffff, #cfe0f5); border-bottom: 2px solid var(--key-border); position: sticky; top: 0; z-index: 20; }
.brand { color: var(--navy); font-weight: 700; text-decoration: none; font-size: 1.15rem; }
.company { font-size: .8rem; color: var(--muted); background: var(--yellow); border: 1px solid var(--grid-line); padding: 2px 8px; border-radius: 3px; max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.langs { margin-left: auto; display: flex; gap: 4px; }
.langs a { text-decoration: none; color: var(--navy); font-weight: 700; padding: 4px 9px; border: 1px solid var(--key-border); border-radius: 3px; background: linear-gradient(#d9e9fb, var(--key)); }
.langs a.active { background: linear-gradient(var(--red-1), var(--red-2)); color: #fff; }

/* hamburger */
.burger { width: 42px; height: 38px; border: 1px solid var(--key-border); border-radius: 4px; background: linear-gradient(#d9e9fb, var(--key)); cursor: pointer; display: grid; align-content: center; justify-items: center; gap: 5px; padding: 0; }
.burger span { display: block; width: 22px; height: 3px; background: var(--navy); border-radius: 2px; }
.drawer { position: fixed; top: 0; left: 0; bottom: 0; width: 280px; background: var(--bg); border-right: 3px solid var(--key-border); padding: 70px 14px 14px; transform: translateX(-100%); transition: transform .2s; z-index: 15; overflow-y: auto; box-shadow: 4px 0 14px rgba(0,0,0,.25); }
.drawer.open { transform: none; }
.drawer a { display: block; margin: 6px 0; padding: 11px 12px; text-decoration: none; color: var(--navy); font-weight: 700; border: 1px solid var(--key-border); border-radius: 3px; background: linear-gradient(#d9e9fb, var(--key)); }
.drawer a:hover { background: linear-gradient(#ffffff, #cfe0f5); }
.drawer a.danger { color: #a40f0f; }
.drawer hr { border: 0; border-top: 1px solid var(--grid-line); margin: 12px 0; }
.backdrop { position: fixed; inset: 0; background: rgba(10, 30, 70, .35); z-index: 14; display: none; }
.backdrop.open { display: block; }

.content { max-width: 1200px; margin: 0 auto; padding: 18px 14px 40px; }
h1 { margin: 0; color: var(--navy); font-size: 1.5rem; }
h2 { margin: 0; color: var(--navy); font-size: 1.1rem; }
h3.sub { color: var(--navy); margin: 14px 0 6px; font-size: .95rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.page-head .spacer { flex: 1; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--key-border); border-radius: 4px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.panel > header { display: flex; align-items: center; gap: 8px; padding: 7px 12px; background: linear-gradient(#ffffff, #cfe0f5); border-bottom: 1px solid var(--key-border); }
.panel > header .spacer { flex: 1; }
.panel .body { padding: 12px; }

/* buttons (keypad style) */
.btn { display: inline-block; padding: 7px 14px; border: 1px solid var(--key-border); border-radius: 3px; background: linear-gradient(#d9e9fb, var(--key)); color: var(--navy); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.06); }
.btn.green { background: linear-gradient(var(--green-1), var(--green-2)); border-color: #5f8a25; color: #1c3a00; }
.btn.red { background: linear-gradient(var(--red-1), var(--red-2)); border-color: #8d1010; color: #fff; }
.btn.orange { background: linear-gradient(#ffc477, var(--orange)); border-color: #b86c0c; color: #3d2300; }
.btn.small { padding: 3px 9px; font-size: .85rem; }

/* alerts */
.alert { padding: 10px 14px; border-radius: 3px; margin-bottom: 14px; border: 1px solid; }
.alert.ok { background: #e7f5d0; border-color: #5f8a25; color: #234500; }
.alert.err { background: #fde3e3; border-color: #a40f0f; color: #6d0909; }
.alert pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; font: .85rem Consolas, monospace; }
.validation-summary-errors, .field-error { color: #a40f0f; }

/* data grid (like the article grid in the till) */
.grid-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--grid-line); }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { background: linear-gradient(#ffffff, #cfe0f5); color: var(--navy); text-align: left; padding: 5px 10px; border: 1px solid var(--grid-line); white-space: nowrap; }
table.grid td { padding: 5px 10px; border: 1px solid #dbe5f3; }
table.grid tbody tr:nth-child(even) { background: var(--yellow); }
table.grid td.actions { white-space: nowrap; text-align: right; width: 1%; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 10px; font-size: .78rem; font-weight: 700; border: 1px solid; }
.badge.on { background: #e1f3c4; border-color: #5f8a25; color: #234500; }
.badge.off { background: #e6e9ee; border-color: #8c97a8; color: #4a5568; }
.yes { color: #3d7a00; font-weight: 700; } .no { color: #a40f0f; font-weight: 700; } .muted { color: var(--muted); }

/* journal cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--key-border); border-radius: 4px; display: flex; flex-direction: column; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.card > header { padding: 8px 12px; background: linear-gradient(#ffffff, #cfe0f5); border-bottom: 1px solid var(--key-border); display: flex; align-items: center; gap: 8px; }
.card > header h2 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .body { padding: 10px 12px; flex: 1; }
.card footer { padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--grid-line); background: var(--bg); }

/* key/value details */
dl.kv { display: grid; grid-template-columns: minmax(130px, 220px) 1fr; margin: 0; gap: 0; }
dl.kv dt { font-weight: 700; color: var(--navy); padding: 4px 10px 4px 0; border-bottom: 1px solid #dbe5f3; }
dl.kv dd { margin: 0; padding: 4px 0; border-bottom: 1px solid #dbe5f3; word-break: break-word; }

/* forms */
form.form { display: grid; gap: 14px; }
fieldset { border: 1px solid var(--key-border); border-radius: 4px; background: var(--panel); margin: 0; padding: 10px 14px 14px; }
legend { color: var(--navy); font-weight: 700; padding: 0 8px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 16px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-weight: 600; color: var(--navy); font-size: .88rem; }
.field input:not([type=checkbox]), .field select { padding: 7px 9px; border: 1px solid var(--key-border); border-radius: 3px; background: var(--yellow); font: inherit; color: var(--text); }
.field input:focus, .field select:focus { outline: 2px solid var(--orange); outline-offset: 0; }
.field.check { flex-direction: row; align-items: center; }
.field.check label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.field.check input { width: 18px; height: 18px; accent-color: var(--key-border); }
.form-actions { display: flex; gap: 8px; }
.picker { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin-bottom: 14px; }
.picker .field { min-width: 260px; }
.empty { padding: 26px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--key-border); border-radius: 4px; }

.connect { max-width: 520px; margin: 40px auto; }
details.raw { margin-top: 10px; }
details.raw summary { cursor: pointer; color: var(--navy); font-weight: 700; }
details.raw pre, table.grid code { white-space: pre-wrap; word-break: break-word; font: .8rem Consolas, monospace; }
details.raw pre { background: #fff; border: 1px solid var(--grid-line); padding: 8px; max-height: 320px; overflow: auto; }

@media (max-width: 600px) { dl.kv { grid-template-columns: 1fr; } .company { display: none; } }

/* ---- mobile ---- */
@media (max-width: 720px) {
    body { font-size: 16px; }
    .topbar { gap: 8px; padding: 6px 8px; }
    .brand { font-size: 1rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .langs { margin-left: 0; gap: 3px; }
    .langs a { padding: 8px 8px; min-width: 38px; text-align: center; }
    .burger { flex: none; }
    .drawer { width: min(86vw, 320px); }
    .content { padding: 12px 10px 32px; }
    h1 { font-size: 1.25rem; }

    /* 16px+ prevents iOS Safari from zooming into focused fields */
    .field input:not([type=checkbox]), .field select { font-size: 16px; min-height: 44px; }
    .field.check label { min-height: 44px; }
    .field.check input { width: 22px; height: 22px; }

    /* comfortable tap targets */
    .btn { min-height: 44px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center; }
    .btn.small { min-height: 44px; padding: 8px 12px; font-size: .9rem; }
    .burger { width: 46px; height: 44px; }

    .page-head > .btn { flex: 1 1 auto; }
    .page-head h1 { flex: 1 0 100%; }
    .page-head .spacer { display: none; }
    .panel > header { flex-wrap: wrap; }
    .cards { grid-template-columns: 1fr; }
    .card footer .btn { flex: 1 1 auto; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; }
    .picker .field { min-width: 0; flex: 1 1 100%; }

    /* tables become stacked cards; cells with data-label show their column name */
    .grid-wrap { overflow: visible; background: transparent; border: 0; }
    table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
    table.grid thead { position: absolute; left: -9999px; }
    table.grid tbody tr { background: #fff; border: 1px solid var(--key-border); border-radius: 4px; margin-bottom: 10px; padding: 4px 0; }
    table.grid tbody tr:nth-child(even) { background: var(--yellow); }
    table.grid td { border: 0; border-bottom: 1px solid #dbe5f3; display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; text-align: right; word-break: break-word; }
    table.grid td:last-child { border-bottom: 0; }
    table.grid td[data-label]::before { content: attr(data-label); font-weight: 700; color: var(--navy); text-align: left; flex: none; max-width: 45%; }
    table.grid td.actions { width: 100%; justify-content: flex-end; text-align: right; }
}

@media (max-width: 380px) {
    .brand { font-size: .9rem; }
    .langs a { min-width: 34px; padding: 8px 6px; }
}
