/* ==========================================================================
   Back office (admin.hmpsandbox.com)
   The businesslike sibling of the travel diary: same stationery family
   (paper, ink, hairlines), none of the scrapbook props. Blue ink is the
   working pen (primary actions), red ink is reserved for destructive ones.
   Data wears a monospace; headings a serif; UI text the system sans.
   House rule: never use em dashes, in copy or comments.
   ========================================================================== */

:root {
    --bg:       #ede9de;
    --panel:    #fbfaf5;
    --panel-2:  #f2efe6;
    --ink:      #2a2722;
    --ink-2:    #5f594c;
    --ink-3:    #837b6b;
    --line:     #d9d3c3;
    --line-2:   #c2bAA6;
    --blue:     #2e5f8f;   /* the working pen */
    --blue-deep:#234b72;
    --red:      #a03e22;   /* the red pen: delete and errors only */
    --green:    #4d7522;
    --amber:    #8f6400;

    --font-ui:   system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-head: Georgia, 'Times New Roman', serif;
    --font-mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;

    --radius: 8px;
    --radius-sm: 5px;
    --shadow: 0 1px 2px rgba(56, 48, 30, 0.08), 0 4px 16px rgba(56, 48, 30, 0.07);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 0.95rem;
    line-height: 1.55;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3 { font-family: var(--font-head); font-weight: 700; line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }

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

code { font-family: var(--font-mono); font-size: 0.85em; }

.icon { width: 17px; height: 17px; display: block; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 2px; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- Chrome ---------------------------------------------------------------- */

.topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 1.25rem;
    flex-wrap: wrap;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 13px;
    height: 13px;
    border: 2px solid var(--blue);
    border-radius: 3px;
    background: linear-gradient(135deg, var(--blue) 50%, transparent 50%);
}
.topnav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.topnav a { color: var(--ink-2); padding: 0.2rem 0; border-bottom: 2px solid transparent; }
.topnav a:hover { color: var(--ink); text-decoration: none; }
.topnav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--blue); }
.topnav .logout { color: var(--ink-3); font-size: 0.88rem; }

.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 1.75rem 1.25rem 3rem; flex: 1; }

.foot { border-top: 1px solid var(--line); color: var(--ink-3); font-size: 0.82rem; text-align: center; }
.foot p { margin: 0.8rem; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .crumb { color: var(--ink-3); font-size: 0.85rem; display: inline-flex; align-items: center; gap: 0.3rem; }
.page-head h1 { margin-bottom: 0.1rem; }
.page-head .sub { color: var(--ink-2); margin: 0; font-size: 0.9rem; }
.page-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

.section-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-3);
    margin: 2rem 0 0.75rem;
}
.section-label:first-child { margin-top: 0; }

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

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.95rem;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--panel);
    color: var(--ink);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 45%, var(--line-2)); }
.btn-danger:hover { background: color-mix(in srgb, var(--red) 7%, var(--panel)); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.84rem; }

/* Icon-only row actions, sized for touch. */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--ink-3);
    cursor: pointer;
    padding: 0;
}
.icon-btn:hover { color: var(--blue); background: var(--panel-2); border-color: var(--line); text-decoration: none; }
.icon-btn.danger:hover { color: var(--red); }

/* --- Notices ---------------------------------------------------------------- */

.notice {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-2);
    background: var(--panel);
    margin-bottom: 1rem;
}
.notice-success { border-color: color-mix(in srgb, var(--green) 45%, var(--line-2)); color: var(--green); }
.notice-error { border-color: color-mix(in srgb, var(--red) 45%, var(--line-2)); color: var(--red); }

/* --- Dashboard --------------------------------------------------------------- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 0.9rem;
}
.table-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem 0.85rem;
    color: inherit;
}
.table-card:hover { border-color: var(--line-2); text-decoration: none; }
.table-card h2 { margin: 0; font-size: 1.05rem; }
.table-card .desc { color: var(--ink-2); font-size: 0.84rem; margin: 0; min-height: 2.4em; }
.table-card .meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.55rem;
    padding-top: 0.55rem;
    border-top: 1px dashed var(--line);
}
.table-card .count { font-family: var(--font-mono); font-size: 0.85rem; color: var(--ink-2); }
.table-card .count strong { color: var(--ink); font-size: 1rem; }
.table-card .count .flag { color: var(--amber); }
.table-card .new-link {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.84rem;
}
/* The whole card is clickable via a stretched link on the title. */
.table-card .card-link::after { content: ''; position: absolute; inset: 0; }

.trip-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.trip-card .desc { min-height: auto; }
.trip-meta,
.trip-counts {
    display: flex;
    gap: 0.6rem 0.9rem;
    flex-wrap: wrap;
    color: var(--ink-2);
    font-size: 0.82rem;
}
.trip-counts { padding-top: 0.35rem; }
.trip-counts strong { color: var(--ink); }

/* --- Data table ---------------------------------------------------------------- */

.toolbar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.searchbox { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.searchbox .icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.searchbox input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2rem;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--panel);
    font: inherit;
    font-size: 0.9rem;
}
.toolbar .spacer { flex: 1; }
.result-note { color: var(--ink-3); font-size: 0.84rem; }

.table-wrapper {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th {
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-3);
    background: var(--panel-2);
    padding: 0.55rem 0.8rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.data-table td {
    padding: 0.55rem 0.8rem;
    border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, var(--panel));
    vertical-align: middle;
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--blue) 4%, var(--panel)); }

.col-actions { width: 84px; }
.row-actions { display: flex; gap: 0.15rem; }
.row-actions form { display: inline; margin: 0; }

.cell-title a { color: var(--ink); font-weight: 600; }
.cell-title a:hover { color: var(--blue); }
.cell-null { color: var(--ink-3); font-style: italic; font-size: 0.82rem; }
.cell-date { color: var(--ink-2); font-size: 0.84rem; white-space: nowrap; }
.cell-color { display: inline-flex; align-items: center; gap: 0.4rem; }

.pill {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 0.06rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--line-2);
    color: var(--ink-3);
}
.pill-yes { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, var(--line-2)); }

.swatch-dot {
    display: inline-block;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--line-2);
    flex: none;
}

.empty-state { padding: 2.5rem 1.5rem; text-align: center; color: var(--ink-2); }
.empty-state .btn { margin-top: 0.8rem; }

.pager { display: flex; align-items: center; gap: 0.6rem; justify-content: flex-end; margin-top: 0.8rem; font-size: 0.86rem; color: var(--ink-2); }

/* --- Forms ---------------------------------------------------------------- */

.form-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    max-width: 760px;
}
.form-group { margin-bottom: 1.1rem; }
.form-group > label { display: block; font-weight: 600; font-size: 0.86rem; margin-bottom: 0.3rem; }
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="datetime-local"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: #fff;
    font: inherit;
    font-size: 0.92rem;
}
.form-group textarea { resize: vertical; font-family: var(--font-mono); font-size: 0.85rem; line-height: 1.5; }
.form-group input[type="file"] {
    width: 100%;
    padding: 0.45rem 0.55rem;
    border: 1px dashed var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    font: inherit;
    font-size: 0.85rem;
}
.form-group input[type="file"]::file-selector-button {
    font: inherit;
    font-size: 0.82rem;
    padding: 0.3rem 0.7rem;
    margin-right: 0.7rem;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: #fff;
    cursor: pointer;
}
.form-group input:focus, .form-group textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 15%, transparent); }
.form-group input[readonly] { background: var(--panel-2); color: var(--ink-2); }
.hint { font-size: 0.8rem; color: var(--ink-3); margin: 0.25rem 0 0; }
.req { color: var(--red); }
.pk-note { font-family: var(--font-mono); font-size: 0.85rem; color: var(--ink-2); background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.45rem 0.7rem; }

.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 22px;
    padding-left: 50px;
    cursor: pointer;
}
.switch input[type="checkbox"] {
    position: absolute;
    left: 0;
    top: 0;
    width: 40px;
    height: 22px;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}
.switch-track {
    position: absolute;
    left: 0;
    top: 0;
    width: 40px;
    height: 22px;
    border-radius: 999px;
    background: var(--line-2);
    transition: background 120ms ease;
    flex: none;
}
.switch-track::after {
    content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
    border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: left 120ms ease;
}
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { left: 21px; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--blue); outline-offset: 2px; }
.switch-label { font-size: 0.84rem; color: var(--ink-3); }

.js-color-pair { display: flex; gap: 0.5rem; align-items: center; }
.js-color-pair input[type="text"] { flex: 1; font-family: var(--font-mono); }
.js-color-pair input[type="color"] {
    width: 44px; height: 38px; padding: 2px; border: 1px solid var(--line-2);
    border-radius: var(--radius-sm); background: #fff; cursor: pointer; flex: none;
}

.form-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 1rem;
    align-items: start;
}
.form-shell > div { min-width: 0; }
.form-shell .form-card { max-width: none; }
.schema-panel {
    position: sticky;
    top: 1rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
}
.schema-panel h2 { font-size: 1rem; margin-bottom: 0.3rem; }
.schema-panel .panel-sub { color: var(--ink-2); font-size: 0.84rem; margin: 0 0 0.8rem; }
.schema-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.45rem; }
.schema-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    font-size: 0.82rem;
}
.schema-list .name { font-family: var(--font-mono); color: var(--ink); }
.schema-list .meta { color: var(--ink-3); text-align: right; }
.schema-list .hidden .name { opacity: 0.6; }
.schema-list .hidden .meta { color: var(--amber); }

.bundle-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 1rem;
    align-items: start;
}
.bundle-main { min-width: 0; }
.bundle-sidebar {
    position: sticky;
    top: 1rem;
    display: grid;
    gap: 1rem;
}
.bundle-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
}
.bundle-panel h2 { font-size: 1rem; margin-bottom: 0.35rem; }
.bundle-panel .panel-sub { color: var(--ink-2); font-size: 0.84rem; margin: 0 0 0.8rem; }
.bundle-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
.bundle-stat {
    padding: 0.6rem 0.7rem;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}
.bundle-stat b { display: block; font-size: 1.05rem; color: var(--ink); }
.bundle-stat span { color: var(--ink-3); font-size: 0.78rem; }
.bundle-section {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-top: 1rem;
}
.bundle-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.bundle-section-head .count { color: var(--ink-3); font-size: 0.82rem; }
.bundle-row {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    padding: 0.9rem;
    margin-bottom: 0.75rem;
}
.bundle-row:last-child { margin-bottom: 0; }
.bundle-row .row-actions { margin-top: 0.7rem; }
.bundle-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}
.bundle-grid .form-group { margin-bottom: 0; }
.bundle-grid .span-2 { grid-column: 1 / -1; }
.bundle-inline-note { color: var(--ink-3); font-size: 0.82rem; margin: 0.2rem 0 0; }

.form-actions { display: flex; gap: 0.7rem; align-items: center; margin-top: 1.4rem; flex-wrap: wrap; }
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--line-2); }

/* --- Login ---------------------------------------------------------------- */

.login-wrap { max-width: 380px; margin: 12vh auto 0; padding: 0 1.25rem; }
.login-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-top: 3px solid var(--blue);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.75rem;
}
.login-card h1 { font-size: 1.3rem; }
.login-card .sub { color: var(--ink-2); font-size: 0.88rem; margin: 0 0 1.2rem; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 0.4rem; }

/* --- Recipe import and export -------------------------------------------------- */

.copy-block .btn { margin-bottom: 0.5rem; }

.prompt-text {
    width: 100%;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    line-height: 1.5;
    color: var(--ink-2);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.7rem;
    resize: vertical;
}

.import-preview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 0.8rem;
}

.import-preview .schema-list { max-height: 18rem; overflow-y: auto; }

/* --- Responsive ---------------------------------------------------------------- */

@media (max-width: 600px) {
    .wrap { padding: 1.25rem 0.9rem 2.5rem; }
    .page-head { align-items: flex-start; flex-direction: column; }
    .data-table td { max-width: 220px; }
    .form-shell, .bundle-layout { grid-template-columns: 1fr; }
    .schema-panel, .bundle-sidebar { position: static; }
    .bundle-grid { grid-template-columns: 1fr; }
    .import-preview { grid-template-columns: 1fr; }
}
