/* RD Stock Office page (decision 33): a desktop layout, separate from the phone
   app's app.css so the phone never changes. Colors: keep in step with app.css. */
:root {
  --bg: #f5f5f4;
  --card: #ffffff;
  --text: #1c1917;
  --muted: #57534e;
  --border: #d6d3d1;
  --row: #fafaf9;
  --hover: #f1f5f9;
  --brand: #0b162a;
  --accent: #c83803;
  --accent-text: #ffffff;
  --bad: #b91c1c;
  --ok: #15803d;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --warn-text: #78350f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
  accent-color: var(--accent);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b162a;
  --card: #15233d;
  --text: #f5f5f4;
  --muted: #a8b3c7;
  --border: #2b3b5a;
  --row: #12203a;
  --hover: #1d2e4d;
  --accent: #d9480f;
  --bad: #f87171;
  --ok: #16a34a;
  --warn: #f59e0b;
  --warn-bg: #422006;
  --warn-text: #fde68a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
}

h2 {
  margin: 0;
  font-size: 1.2rem;
}

h3 {
  margin: 0;
  font-size: 1rem;
}

p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.error {
  color: var(--bad);
}

.error:empty,
.status:empty {
  display: none;
}

.good {
  color: var(--ok);
}

/* Buttons and fields */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button.secondary,
.button.secondary,
.button {
  color: var(--text);
  background: var(--card);
  border-color: var(--border);
}

.button.primary {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

button.ghost {
  min-height: 32px;
  padding: 4px 8px;
  color: var(--muted);
  background: none;
  border-color: transparent;
}

button.link {
  min-height: 0;
  padding: 0;
  color: var(--accent);
  background: none;
  border: none;
  font-weight: 600;
}

button.danger {
  color: var(--bad);
  background: var(--card);
  border-color: var(--bad);
}

input,
select,
textarea {
  min-height: 36px;
  padding: 6px 10px;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 7px;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

input[type="checkbox"] {
  min-height: 0;
  width: 17px;
  height: 17px;
  margin: 0;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

label.field input,
label.field select,
label.field textarea {
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text);
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.tag.warn {
  color: var(--bad);
  border-color: var(--bad);
}

.tag.good {
  color: var(--ok);
  border-color: var(--ok);
}

/* Sign-in gate */
.gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 420px;
  margin: 15vh auto 0;
  padding: 0 16px;
  text-align: center;
}

/* Layout: menu on the left, the page on the right */
.office {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100vh;
  padding: 16px 12px;
  color: #e2e8f0;
  background: var(--brand);
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
}

.side-brand img {
  border-radius: 7px;
}

.side-brand small {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: #94a3b8;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav a {
  padding: 8px 10px;
  color: #cbd5e1;
  text-decoration: none;
  border-radius: 7px;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav a[aria-current="page"] {
  color: #fff;
  font-weight: 700;
  background: var(--accent);
}

.nav .nav-head {
  margin: 10px 10px 2px;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #64748b;
}

.side-foot {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
  padding: 0 6px;
  font-size: 0.85rem;
}

.side-foot .muted {
  color: #94a3b8;
}

.side-link {
  color: #cbd5e1;
}

.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
  padding: 0;
  border: none;
}

.theme-switch legend {
  margin-bottom: 4px;
  font-size: 0.75rem;
  color: #94a3b8;
}

.theme-switch button {
  min-height: 28px;
  padding: 2px 4px;
  font-size: 0.8rem;
  font-weight: 500;
  color: #cbd5e1;
  background: transparent;
  border: 1px solid #334155;
  border-radius: 0;
}

.theme-switch button:first-of-type {
  border-radius: 6px 0 0 6px;
}

.theme-switch button:last-of-type {
  border-radius: 0 6px 6px 0;
}

.theme-switch button + button {
  border-left: none;
}

.theme-switch button[aria-pressed="true"] {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 20px 24px 48px;
}

/* A page: title, toolbar, then its tables and cards. Each visit gets a fresh .page box. */
.page {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

.page-head h1 {
  margin-right: auto;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
}

.toolbar .grow {
  flex: 1 1 260px;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  color: var(--muted);
}

.summary strong {
  color: var(--text);
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat .n {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tabs button {
  min-height: 34px;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
}

.tabs button[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* Tables */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 220px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.table-wrap.short {
  max-height: none;
}

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

table.data th,
table.data td {
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

table.data th {
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  background: var(--card);
  user-select: none;
}

table.data th.sortable {
  cursor: pointer;
}

table.data th.sortable:hover {
  color: var(--text);
}

table.data th .arrow {
  margin-left: 4px;
  color: var(--accent);
}

table.data tbody tr:nth-child(even) td {
  background: var(--row);
}

table.data tbody tr.clickable {
  cursor: pointer;
}

table.data tbody tr.clickable:hover td,
table.data tbody tr.selected td {
  background: var(--hover);
}

table.data tbody tr.done td {
  opacity: 0.55;
}

table.data .num {
  text-align: right;
  white-space: nowrap;
}

table.data .nowrap {
  white-space: nowrap;
}

table.data .bad {
  color: var(--bad);
  font-weight: 700;
}

table.data tfoot td {
  position: sticky;
  bottom: 0;
  font-weight: 700;
  background: var(--card);
  border-top: 2px solid var(--border);
}

.table-more {
  display: flex;
  justify-content: center;
  padding: 10px;
}

.empty {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

/* Column picker */
details.menu {
  position: relative;
}

details.menu > summary {
  list-style: none;
}

details.menu > summary::-webkit-details-marker {
  display: none;
}

details.menu .menu-body {
  position: absolute;
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
  margin-top: 4px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

details.menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  white-space: nowrap;
}

/* Side panel with one item */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(480px, 100vw);
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.18);
}

.drawer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-bar h2 {
  margin-right: auto;
}

.drawer-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
}

.drawer-body .photo {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: var(--bg);
  border-radius: 8px;
}

.kv {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 4px 12px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.section-title {
  margin-top: 4px;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Catalog picker and other dialogs */
dialog.modal {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 16px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

dialog.modal[open] {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.modal-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.modal-bar h2 {
  margin-right: auto;
}

.picker-results {
  overflow: auto;
  max-height: 55vh;
}

.check-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.check-list label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 400;
}

/* A short message in the corner after saving */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  z-index: 40;
  padding: 10px 16px;
  color: #fff;
  background: #0f172a;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  transform: translateX(-50%);
}

.toast.bad {
  background: var(--bad);
}

/* Narrow windows: the menu goes on top; tables scroll sideways */
@media (max-width: 900px) {
  .office {
    grid-template-columns: minmax(0, 1fr);
  }

  .side {
    position: static;
    height: auto;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav .nav-head {
    display: none;
  }

  .main {
    padding: 16px;
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media print {
  .side,
  .toolbar,
  .drawer,
  .no-print {
    display: none !important;
  }

  .office {
    display: block;
  }

  .table-wrap {
    max-height: none;
    overflow: visible;
    border: none;
  }
}
