:root {
  --teal: #00807f;
  --teal-dark: #00605f;
  --teal-soft: #e4f2f2;
  --red: #d23b3b;
  --green: #18955a;
  --ink: #123332;
  --muted: #5e7473;
  --line: #dbe6e6;
  --bg: #f3f7f7;
  --surface: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(18, 51, 50, .06), 0 8px 24px rgba(18, 51, 50, .06);
  font-family: "Plus Jakarta Sans", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
h1, h2 { margin: 0; }
em { font-style: normal; font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 4px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; font-weight: 500; }
.center { text-align: center; }

/* Buttons & inputs */
button, input, select, textarea { font: inherit; color: inherit; }
.btn-primary, .btn-secondary, .btn-ghost {
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; font-size: 14px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; white-space: nowrap; transition: background .15s, transform .05s;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-primary.green { background: var(--green); }
.btn-primary.green:hover { background: #127a49; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--teal-soft); color: var(--teal-dark); }
.btn-secondary:hover { background: #d3e9e9; }
.btn-ghost { background: transparent; color: var(--teal-dark); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--teal-soft); }
button:active { transform: translateY(1px); }
.block { width: 100%; padding: 14px; font-size: 15px; }

input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: #fff; font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 128, 127, .15); }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 18px; padding: 36px 28px;
  box-shadow: var(--shadow); display: grid; gap: 14px; text-align: center;
}
.login-logo { width: 200px; margin: 0 auto 6px; }
.login-card h1 { font-size: 20px; }
.login-card p { margin: 0; }
.error { color: var(--red); font-size: 13px; font-weight: 600; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand img { height: 26px; }
.brand .divider { width: 1px; height: 22px; background: var(--line); }
.app-name { font-weight: 700; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Layout */
.layout {
  max-width: 1280px; margin: 0 auto; padding: 24px; display: grid; gap: 20px;
  grid-template-columns: minmax(0, 1fr);
}
/* The sticky preview is confined to .workspace, so it can never slide over the history card. */
.workspace {
  display: grid; gap: 20px; align-items: start;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; }
.card-head input[type=search] { max-width: 320px; }
.badge { font-size: 12px; font-weight: 700; color: var(--teal-dark); background: var(--teal-soft); padding: 4px 10px; border-radius: 99px; }

/* Tabs */
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); padding: 4px; border-radius: 12px; margin-bottom: 20px; }
.tab {
  border: 0; background: transparent; padding: 10px; border-radius: 9px; font-weight: 700; cursor: pointer;
  color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 8px;
}
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(18, 51, 50, .12); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.red { background: var(--red); }
.dot.green { background: var(--green); }
.count { background: var(--red); color: #fff; font-size: 11px; border-radius: 99px; padding: 1px 7px; }

/* Form */
.pane { display: grid; gap: 18px; }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
.label { font-size: 13px; font-weight: 700; display: flex; align-items: baseline; gap: 4px; }
.label .hint { margin-left: auto; }
.with-btn { display: flex; gap: 8px; }
.with-btn input { flex: 1; min-width: 0; }
.with-btn > button { flex: none; }
/* Date/time pickers get their own row, bigger text, and a fixed-width button that can't be covered. */
.datetime input { font-size: 16px; font-weight: 700; padding: 11px 12px; }
.datetime > button { min-width: 72px; }
.when {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; font-weight: 600; color: var(--muted);
}
.when:empty { display: none; }
.when .d { color: var(--teal-dark); font-weight: 800; font-size: 15px; }
.when .t { color: var(--ink); font-weight: 800; font-size: 15px; }
.status { font-size: 12px; font-weight: 600; min-height: 16px; }
.status.ok { color: var(--green); }
.status.bad { color: var(--red); }
.form-error { margin: 0; background: #fdecec; color: var(--red); padding: 10px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; text-align: center; padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; font-weight: 700; cursor: pointer; color: var(--muted); height: 100%;
}
.segmented input:checked + span { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px rgba(0, 128, 127, .2); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 99px;
  padding: 7px 8px 7px 14px; font-size: 13px; font-weight: 700; cursor: pointer; background: #fff; color: var(--muted);
  user-select: none;
}
.chip .check {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center;
  font-size: 10px; color: transparent;
}
.chip.on { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }
.chip.on .check { background: var(--teal); border-color: var(--teal); color: #fff; }
.chip .x {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 16px; line-height: 1;
  border-radius: 50%;
}
.chip .x:hover { color: var(--red); }
.chip:not(:has(.x)) { padding-right: 14px; }

.summary {
  background: var(--bg); border-radius: 12px; padding: 14px 16px; font-size: 13px; display: grid; gap: 6px;
  border-left: 4px solid var(--red);
}
.summary b { color: var(--muted); font-weight: 700; display: inline-block; min-width: 92px; }

/* Preview */
.preview-card { position: sticky; top: 84px; z-index: 1; }
/* Keep the whole preview card (canvas + action buttons) inside the viewport while it is sticky. */
.canvas-wrap {
  border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #fff;
  width: 100%; max-width: max(300px, calc(100vh - 380px)); margin: 0 auto;
}
canvas#banner { display: block; width: 100%; height: auto; aspect-ratio: 1 / 1; }
.ready {
  margin-top: 14px; display: grid; gap: 12px; background: #e9f7f0; border: 1px solid #bfe6d2;
  border-radius: 12px; padding: 14px; animation: rise .2s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.ready-text { display: grid; gap: 2px; font-size: 13px; color: var(--muted); }
.ready-text strong { color: var(--ink); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
#previewHint { margin: 12px 0 0; }

/* History */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.nowrap { white-space: nowrap; }
td .desc { color: var(--muted); font-size: 12px; margin-top: 2px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td .sub { color: var(--muted); font-size: 12px; font-weight: 600; margin-top: 2px; }
.pill { display: inline-block; font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.pill.open { background: #fdecec; color: var(--red); }
.pill.resolved { background: #e3f5ec; color: var(--green); }
.pill.type { background: var(--bg); color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
/* Keep the actions reachable when the table scrolls sideways. */
th:last-child, td:last-child { position: sticky; right: 0; background: var(--surface); box-shadow: -10px 0 10px -10px rgba(18, 51, 50, .25); }
.row-actions button { padding: 6px 10px; font-size: 12px; }
.btn-danger { color: var(--red); }

/* Toast */
/* Drops in just under the top bar so it never covers the form or banner buttons. */
.toast {
  position: fixed; left: 50%; top: 76px; transform: translate(-50%, -12px); opacity: 0; visibility: hidden;
  pointer-events: none; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(18, 51, 50, .25);
  transition: opacity .2s, transform .2s, visibility 0s linear .2s;
  width: max-content; max-width: min(520px, calc(100% - 32px)); text-align: center; z-index: 20;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition: opacity .2s, transform .2s; }
.toast.error { background: var(--red); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 980px) {
  .layout { padding: 16px; gap: 16px; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .preview-card { position: static; }
  .canvas-wrap { max-width: 560px; }
}
@media (max-width: 560px) {
  .topbar { padding: 12px 16px; }
  .brand .divider, .app-name { display: none; }
  .segmented { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .datetime input { font-size: 15px; padding: 10px; }
  .datetime > button { min-width: 0; padding: 10px 12px; }
}
