:root {
  --ink: #1f2328;
  --ink-soft: #57606a;
  --line: #d8dee4;
  --paper: #ffffff;
  --wash: #f5f6f8;
  --accent: #b5471b;        /* forge orange */
  --accent-ink: #ffffff;
  --accent-soft: #fbeee8;
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--wash); line-height: 1.5; font-size: 16px; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.5rem 0 .25rem; }
.lead { color: var(--ink-soft); margin: 0 0 1.5rem; }
.small { font-size: .9rem; }
.help { color: var(--ink-soft); font-size: .9rem; margin: .25rem 0 .75rem; }
.muted, tr.muted td { color: var(--ink-soft); }
.right { text-align: right; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  background: var(--paper); border-bottom: 1px solid var(--line); padding: .75rem 1.25rem;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-mark { width: 18px; height: 18px; border-radius: 4px; background: var(--accent); display: inline-block; }
.nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.nav a { color: var(--ink); text-decoration: none; }
.nav a:hover { color: var(--accent); }

.page { max-width: 1000px; margin: 0 auto; padding: 2rem 1.25rem 3rem; }
.auth { padding: 3rem 1rem; }
.auth-card { max-width: 420px; margin: 0 auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem; }
.card.narrow { max-width: 460px; }
.card.empty { border-style: dashed; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }
.footer { text-align: center; color: var(--ink-soft); font-size: .85rem; padding: 1.5rem; }
.footer a { color: var(--ink-soft); }

.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field-check label { font-weight: 400; display: flex; gap: .5rem; align-items: flex-start; }
.field-check input { margin-top: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=tel], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad); }
.error { color: var(--bad); font-size: .9rem; margin-top: .25rem; }
.form-error { background: var(--bad-soft); color: var(--bad); border-radius: 6px; padding: .6rem .8rem; margin-bottom: 1rem; }
.form-error p { margin: 0; }
.helptext, .field ul { color: var(--ink-soft); font-size: .85rem; }

.button {
  display: inline-block; padding: .55rem 1rem; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.button:hover { border-color: var(--ink-soft); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { filter: brightness(.95); }
.button.danger { color: var(--bad); }
.button.small { padding: .25rem .6rem; font-size: .85rem; }
.button.wide { width: 100%; }
button.link { background: none; border: 0; padding: 0; color: var(--ink); font: inherit; cursor: pointer; }
button.link:hover { color: var(--accent); }
form.inline { display: inline; }

.messages { list-style: none; padding: 0; margin: 0 0 1.5rem; }
.msg { padding: .6rem .9rem; border-radius: 6px; margin-bottom: .5rem; background: var(--accent-soft); }
.msg-success { background: var(--ok-soft); color: var(--ok); }
.msg-error { background: var(--bad-soft); color: var(--bad); }

.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--ink-soft); font-weight: 600; font-size: .85rem; }
.table td.right, .table th.right { text-align: right; }
.actions form + form { margin-left: .3rem; }
@media (max-width: 760px) {
  .table thead { display: none; }
  .table tr { display: block; border-bottom: 1px solid var(--line); padding: .5rem 0; }
  .table td { display: block; border: 0; padding: .15rem 0; text-align: left !important; }
}

.tag { font-size: .75rem; background: var(--wash); border: 1px solid var(--line); border-radius: 999px; padding: 0 .45rem; color: var(--ink-soft); }
.status { font-size: .8rem; border-radius: 999px; padding: .1rem .55rem; font-weight: 600; }
.status-active { background: var(--ok-soft); color: var(--ok); }
.status-invited { background: var(--accent-soft); color: var(--accent); }
.status-removed { background: var(--wash); color: var(--ink-soft); }

.inline-form { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: .75rem; align-items: end; }
.inline-form .field { margin: 0; }
.inline-form .form-error { grid-column: 1 / -1; }
@media (max-width: 760px) { .inline-form { grid-template-columns: 1fr; } }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 1rem; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; }
.signature, .logo-preview { max-width: 240px; max-height: 120px; border: 1px solid var(--line); border-radius: 6px; padding: .5rem; background: #fff; }

.prose { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem; max-width: 760px; }
.draft { background: var(--accent-soft); color: var(--accent); padding: .5rem .75rem; border-radius: 6px; }

.qr svg { width: 220px; height: 220px; display: block; }
code.key { font-size: 1rem; letter-spacing: .08em; word-break: break-all; background: var(--wash); padding: .3rem .5rem; border-radius: 4px; }
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, max-content); gap: .4rem 1.5rem; font-size: 1.1rem; }
.msg-warning { background: var(--accent-soft); color: var(--accent); }
@media print { .topbar, .footer, .button { display: none; } }

/* Jobs */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .lead { margin-bottom: 0; }
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumbs { font-size: .9rem; color: var(--ink-soft); margin: 0 0 .5rem; }
.crumbs a { color: var(--ink-soft); }
.search { display: flex; gap: .5rem; margin-bottom: 1rem; }
.search input { flex: 1; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .table th:first-child, .card.flush .table td:first-child { padding-left: 1.25rem; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--wash); }
.table.jobs a { color: var(--ink); text-decoration: none; }
.status-draft { background: var(--wash); color: var(--ink-soft); }
.status-generating { background: var(--accent-soft); color: var(--accent); }
.status-generated { background: var(--ok-soft); color: var(--ok); }
.status-failed { background: var(--bad-soft); color: var(--bad); }
.card.narrow-wide { max-width: 640px; }
.button.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
button[disabled], .button[disabled] { opacity: .5; cursor: not-allowed; }
.pre { white-space: pre-line; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }

.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.75rem 1rem; text-align: center; cursor: pointer; background: var(--wash); margin: .5rem 0 1rem; }
.dropzone p { margin: .2rem 0; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.link-label { color: var(--accent); text-decoration: underline; cursor: pointer; }
.upload-status { margin-bottom: 1rem; }
.progress { height: 8px; background: var(--wash); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-list { list-style: none; padding: 0; margin: .5rem 0 0; max-height: 220px; overflow: auto; font-size: .85rem; }
.upload-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; border-bottom: 1px solid var(--wash); }
.upload-list li.ok .u-state { color: var(--ok); }
.upload-list li.bad .u-state { color: var(--bad); }
.u-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.photo-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .9rem; }
.photo-tile { font-size: .8rem; }
.photo-tile img, .note-tile { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; background: var(--wash); }
.note-tile { display: flex; align-items: center; justify-content: center; color: var(--ink-soft); font-weight: 700; letter-spacing: .1em; }
.photo-name { margin-top: .3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Reports */
.notice { background: var(--accent-soft); border-radius: 6px; padding: .75rem 1rem; margin: .75rem 0; }
.not-added { margin: .5rem 0; padding-left: 1.1rem; max-height: 260px; overflow: auto; }
.not-added li { margin-bottom: .4rem; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.file-form { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.file-form input[type=file] { font-size: .85rem; max-width: 230px; }
code { background: var(--wash); padding: 0 .25rem; border-radius: 3px; font-size: .85em; }

.upload-list li.warn .u-state { color: var(--accent); }
.upload-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: .25rem 0; }
.upload-actions:empty { display: none; }
.filters { display: flex; gap: .4rem; flex-wrap: wrap; }
pre.detail { white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; background: var(--wash); padding: .6rem; border-radius: 6px; font-size: .78rem; }
.table.problems td { vertical-align: top; }

/* Naming photos */
.rename-list { list-style: none; margin: 0; padding: 0; }
.rename-row { display: grid; grid-template-columns: 180px 1fr; gap: 1rem; align-items: center; padding: .75rem 0; border-bottom: 1px solid var(--line); }
.rename-row:last-child { border-bottom: 0; }
.rename-row img, .rename-row .note-tile { width: 180px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; background: var(--wash); }
.rename-row.has-error input { border-color: var(--bad); }
.rename-old { word-break: break-all; }
.rename-input { display: flex; gap: .4rem; align-items: center; margin-top: .25rem; }
.rename-input input { flex: 1; min-width: 0; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.field-error { color: var(--bad); margin: .25rem 0 0; }
.tag-warn { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.sticky-actions { position: sticky; bottom: 0; background: var(--paper); padding: .75rem 0 .25rem; border-top: 1px solid var(--line); display: flex; gap: .5rem; }
.photo-tile.needs-name img { outline: 2px solid var(--accent); outline-offset: -2px; }
.tile-actions { display: flex; gap: .6rem; align-items: baseline; }
@media (max-width: 560px) {
  .rename-row { grid-template-columns: 1fr; }
  .rename-row img, .rename-row .note-tile { width: 100%; }
}

/* Unsaved changes */
.unsaved-note { margin-left: .75rem; color: var(--accent); font-size: .9rem; font-weight: 600; }
.unsaved-note::before { content: "● "; }

/* Billing */
.billing-banner { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 6px; padding: .6rem .9rem; margin-bottom: 1rem; }
.billing-banner-stop { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.billing-banner a { font-weight: 600; margin-left: .4rem; }

/* Sidebar layout */
.sidebar { display: none; }
.mobilebar { display: none; }
@media (min-width: 900px) {
  body.has-sidebar { padding-left: 248px; }
  .has-sidebar .sidebar { display: flex; }
  .has-sidebar .page { max-width: 1100px; }
}
.has-sidebar .sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 248px; flex-direction: column;
  background: var(--paper); border-right: 1px solid var(--line); padding: 1rem .75rem; overflow-y: auto; z-index: 20;
}
.side-brand { padding: .25rem .5rem 1rem; font-size: 1.1rem; }
.side-user { display: flex; align-items: center; gap: .65rem; padding: .85rem .5rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: .75rem; }
.avatar { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .95rem; letter-spacing: .02em; }
.side-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.side-user-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-text span { color: var(--ink-soft); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-nav { display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.side-nav a, .side-logout button {
  display: flex; align-items: center; gap: .65rem; padding: .55rem .6rem; border-radius: 6px;
  color: var(--ink); text-decoration: none; font: inherit; font-size: .95rem;
}
.side-nav a:hover, .side-logout button:hover { background: var(--wash); color: var(--accent); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-nav .icon, .side-logout .icon { flex: 0 0 18px; }
.side-heading { margin: 1rem .6rem .3rem; font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.side-logout { border-top: 1px solid var(--line); padding-top: .5rem; margin-top: .75rem; }
.side-logout button { width: 100%; background: none; border: 0; cursor: pointer; text-align: left; }
@media (max-width: 899px) {
  .has-sidebar .mobilebar { display: flex; align-items: center; justify-content: space-between; background: var(--paper);
    border-bottom: 1px solid var(--line); padding: .6rem 1rem; position: sticky; top: 0; z-index: 15; }
  .menu-button { display: inline-flex; align-items: center; gap: .4rem; background: none; border: 1px solid var(--line);
    border-radius: 6px; padding: .35rem .6rem; font: inherit; cursor: pointer; color: var(--ink); }
  body.sidebar-open .sidebar { display: flex; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .25); }
}
@media print { .sidebar, .mobilebar { display: none !important; } body.has-sidebar { padding-left: 0; } }

/* Calendar */
.card.flush { padding: 0; overflow: hidden; }
.cal-head { display: flex; align-items: center; gap: .5rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.cal-head h2 { margin: 0 .5rem; min-width: 9.5rem; text-align: center; }
.cal { display: flex; flex-direction: column; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-days div { padding: .45rem .5rem; font-size: .78rem; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--line); }
.cal-cell { min-height: 108px; padding: .35rem .4rem .5rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell.other { background: var(--wash); }
.cal-cell.other .cal-date span { color: var(--ink-soft); opacity: .6; }
.cal-date { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; font-weight: 600; }
.cal-cell.today .cal-date span { background: var(--accent); color: var(--accent-ink); border-radius: 999px; min-width: 1.6rem; height: 1.6rem; display: inline-flex; align-items: center; justify-content: center; padding: 0 .3rem; }
.cal-add { color: var(--ink-soft); text-decoration: none; opacity: 0; font-size: 1.05rem; line-height: 1; padding: 0 .25rem; }
.cal-cell:hover .cal-add, .cal-add:focus { opacity: 1; }
.cal-job { display: block; text-decoration: none; color: var(--ink); background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 4px; padding: .2rem .35rem; font-size: .78rem; line-height: 1.25; overflow: hidden; }
.cal-job strong, .cal-job span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-job span { color: var(--ink-soft); }
.cal-job.status-generated { background: var(--ok-soft); border-left-color: var(--ok); }
.cal-job.status-failed { background: var(--bad-soft); border-left-color: var(--bad); }
.cal-job:hover { filter: brightness(.96); }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: .5rem 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: baseline; }
.plain-list li:last-child { border-bottom: 0; }
@media (max-width: 700px) {
  .cal-cell { min-height: 56px; padding: .25rem; }
  .cal-job span { display: none; }
  .cal-job strong { font-weight: 600; font-size: .7rem; }
  .cal-days div { font-size: .68rem; padding: .35rem .25rem; }
  .cal-add { display: none; }
}
