:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #dfe3e8;
  --border-strong: #c6ccd4;
  --text: #1b1f24;
  --muted: #656d76;
  --accent: #2f6fd0;
  --accent-text: #ffffff;
  --overdue: #b3261e;
  --overdue-bg: #fdeceb;
  --soon: #9a6400;
  --soon-bg: #fdf4e3;
  --ok: #1f7a44;
  --ok-bg: #edf7f1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #14171a;
    --surface: #1c2024;
    --surface-2: #22262b;
    --border: #2f353c;
    --border-strong: #414952;
    --text: #e6e9ec;
    --muted: #9aa4af;
    --accent: #5b9bf8;
    --accent-text: #0d1117;
    --overdue: #f4756b;
    --overdue-bg: #35211f;
    --soon: #e0aa4a;
    --soon-bg: #332a1b;
    --ok: #62c98c;
    --ok-bg: #1a2b21;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #14171a;
  --surface: #1c2024;
  --surface-2: #22262b;
  --border: #2f353c;
  --border-strong: #414952;
  --text: #e6e9ec;
  --muted: #9aa4af;
  --accent: #5b9bf8;
  --accent-text: #0d1117;
  --overdue: #f4756b;
  --overdue-bg: #35211f;
  --soon: #e0aa4a;
  --soon-bg: #332a1b;
  --ok: #62c98c;
  --ok-bg: #1a2b21;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

/* A display rule on an element would otherwise defeat the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 clamp(12px, 3vw, 32px) 64px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 22px 0 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-size: 14px;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }

.btn:disabled,
.btn:disabled:hover {
  opacity: .45;
  cursor: not-allowed;
  filter: none;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn-primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn-primary:disabled:hover { filter: none; }

.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface); color: var(--text); }

.btn-danger-ghost { border-color: transparent; background: transparent; color: var(--overdue); }
.btn-danger-ghost:hover { background: var(--overdue-bg); }

.btn-small { padding: 5px 10px; font-size: 13px; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.theme-toggle-icon {
  width: 1.1em;
  text-align: center;
  line-height: 1;
}

/* Icon-only, so it stays square next to the two text buttons. */
.btn-ct {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
}

.btn-ct .ct-mark { display: block; }

/* ---------- menu ---------- */

.menu { position: relative; }

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 210px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.menu-panel a,
.menu-panel button {
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}

.menu-panel a:hover,
.menu-panel button:hover { background: var(--surface-2); }

/* ---------- banner ---------- */

.banner {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
}

.banner.error { background: var(--overdue-bg); border-color: var(--overdue); color: var(--overdue); }
.banner.info { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }

/* ---------- summary ---------- */

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.stat.is-overdue .stat-value { color: var(--overdue); }
.stat.is-soon .stat-value { color: var(--soon); }

/* ---------- controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.controls input[type="search"] {
  flex: 1 1 260px;
  min-width: 200px;
}

input, select, textarea {
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

textarea { resize: vertical; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}

.check input { margin: 0; }

/* ---------- list ---------- */

.group { margin-bottom: 22px; }

.group-head {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin: 0 2px 8px;
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.group-count {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  opacity: .8;
}

.group.overdue .group-head { color: var(--overdue); }
.group.soon .group-head { color: var(--soon); }

.card {
  display: grid;
  grid-template-columns: 5px 1fr auto;
  align-items: center;
  gap: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 7px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-stripe { align-self: stretch; background: var(--border); }
.card.is-overdue .card-stripe { background: var(--overdue); }
.card.is-soon .card-stripe { background: var(--soon); }
.card.is-ok .card-stripe { background: var(--ok); }
.card.is-inactive { opacity: .62; }

.card-body { padding: 11px 0; min-width: 0; }

.card-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}

.card-title a { color: inherit; }

.card-desc {
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
  /* Single line: the full text is in the tooltip and the dialog. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
}

.card-actions {
  display: flex;
  gap: 6px;
  padding-right: 12px;
  flex-shrink: 0;
}

/* On a phone the actions drop below the text instead of squeezing it. */
@media (max-width: 620px) {
  .card {
    grid-template-columns: 5px 1fr;
    row-gap: 0;
  }

  .card-body { padding: 10px 12px 8px 0; }

  .card-actions {
    grid-column: 2;
    padding: 0 12px 11px 0;
    justify-content: flex-end;
  }

  .card-actions .btn { flex: 0 0 auto; }
}

.due {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.card.is-overdue .due { color: var(--overdue); }
.card.is-soon .due { color: var(--soon); }

.tag {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: none;
}

/* Reference numbers read better with even digit spacing. */
.tag-contract {
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}

.tag.status-paused { background: var(--soon-bg); color: var(--soon); border-color: transparent; }
.tag.status-archived { background: var(--surface-2); }

.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.empty h2 { margin: 0 0 6px; font-size: 17px; color: var(--text); }
.empty p { margin: 0 0 4px; font-size: 14px; }

/* ---------- dialogs ---------- */

.dialog {
  width: min(680px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
}

.dialog::backdrop { background: rgba(12, 16, 22, .45); }

.dialog form { padding: 20px 22px 16px; }

.dialog h2 { margin: 0 0 4px; font-size: 18px; }

.dialog-lead { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto !important; }
}

.span2 { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.field > span {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.field em { font-style: normal; font-weight: 400; opacity: .75; }

/* What this field becomes in Connecteam. The mark is a data URI so a label
   costs no request and still shows on a NAS with no route to the internet —
   and so the SVG is written once rather than on every field. */
.ct-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
  font-style: normal;
  font-weight: 500;
  font-size: 11.5px;
  color: #2E93E0;
  white-space: nowrap;
}

.ct-field::before {
  content: '';
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  background: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 12C9.8 8.8 6 9.2 6 12s3.8 3.2 6 0 6-3.2 6 0-3.8 3.2-6 0Z' fill='none' stroke='%2333A7FF' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E")
    no-repeat center / contain;
}

/* Fields that never leave the app: stated rather than left to be guessed at. */
.ct-field.is-none {
  color: var(--muted);
  opacity: .7;
}

.ct-field.is-none::before { opacity: .35; filter: grayscale(1); }

.section-head {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

/* Collapsible address blocks: open while empty, folded once filled. */
.block {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  min-width: 0;
}

.block > summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  padding: 2px 0;
  border-radius: 6px;
}

/* Safari draws its own triangle unless this is removed. */
.block > summary::-webkit-details-marker { display: none; }

.block > summary::before {
  content: '›';
  flex: none;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  transition: transform .15s ease;
}

.block[open] > summary::before { transform: rotate(90deg); }

.block > summary:hover .block-title { color: var(--text); }
.block > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.block-title {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.block-summary {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  opacity: .85;
  /* One line only: the point is to shrink the form, not restate it. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Redundant once the fields themselves are visible. */
.block[open] .block-summary { display: none; }

.block > .grid { padding-top: 12px; }

.field .row { display: flex; gap: 6px; align-items: center; }
.field .row select { flex: 1; }
/* An input sharing its row with a button still takes the space that is left. */
.field .row > input { flex: 1; min-width: 0; }
.field .row > .btn { flex: 0 0 auto; }
.prefix { font-size: 13px; color: var(--muted); }
.tiny { width: 68px; }

.check-block { gap: 6px; }

.next-preview {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--muted);
}

.form-error {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--overdue-bg);
  color: var(--overdue);
  font-size: 13.5px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--border);
}

.spacer { flex: 1; }

.import-report {
  margin-top: 14px;
  padding: 11px 13px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13.5px;
  max-height: 220px;
  overflow-y: auto;
}

.import-report ul { margin: 7px 0 0; padding-left: 19px; }
.import-report li { margin-bottom: 3px; color: var(--muted); }
.import-report strong { color: var(--text); }

/* ---------- sign-in ---------- */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: min(380px, 100%);
  padding: 26px 26px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 0; font-size: 21px; }
.login-card .subtitle { margin: 2px 0 20px; }
.login-card .field { margin-bottom: 14px; }

.login-theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
}

.btn-block { width: 100%; justify-content: center; margin-top: 4px; }

/* ---------- user menu ---------- */

.menu-heading {
  padding: 6px 10px 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* ---------- administration ---------- */

.dialog-wide { width: min(760px, calc(100vw - 24px)); }

.tabs {
  display: flex;
  gap: 4px;
  margin: 14px 0 16px;
  border-bottom: 1px solid var(--border);
}

.tab {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.admin-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 0 8px 6px 0;
  font-weight: 700;
}

.admin-table td {
  padding: 8px 8px 8px 0;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table select { padding: 4px 6px; font-size: 13px; }

.admin-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.muted-small { font-size: 12px; color: var(--muted); margin-top: 2px; }

.new-block {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.new-block > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 0 10px;
}

.inline-actions { margin-top: 10px; padding-top: 0; border-top: 0; }

.key-reveal {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ok-bg);
  border: 1px solid var(--ok);
  font-size: 13.5px;
}

.key-reveal p { margin: 0 0 8px; color: var(--ok); }

.key-reveal code {
  display: block;
  padding: 9px 11px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12.5px;
  word-break: break-all;
  user-select: all;
}

/* ---------- sync report ---------- */

.sync-report {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13.5px;
  max-height: 260px;
  overflow-y: auto;
}

.sync-report p { margin: 0 0 8px; }
.sync-report ul { margin: 0 0 10px; padding-left: 18px; }
.sync-report li { margin-bottom: 2px; }
.sync-report .ok-line { color: var(--ok); font-weight: 600; }

.ct-settings { margin-top: 14px; }
#ct-instances { min-height: 92px; }

/* ---------- footer ---------- */

.foot {
  margin-top: 28px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}
