/* TOM Production UI — shared tokens & layout (Shop, Production Review, All Drawings) */

:root {
  --bg: #C0B8AB;
  --surface: #F2EBDD;
  --surface-2: #EAE0CC;
  --surface-inset: #EAE0CC;
  --border: #D9CFB8;
  --border-2: #C9BCA0;
  --text: #2E2A24;
  --text-2: #5A5048;
  --muted: #8A7E72;
  --accent: #C97B5C;
  --accent-deep: #A85E40;
  --green: #059669;
  --hold: #d97706;
  --danger: #b91c1c;
  --info: #1d4ed8;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  --radius-sm: 8px;
  --radius-card: 12px;
  --radius-shell: 16px;

  --page-max: min(1680px, 96vw);
  --page-max-shop: min(1920px, 98vw);
  --header-sticky: 72px;
  --touch-min: 44px;
}

* { box-sizing: border-box; }

body.tom-production-ui {
  font-family: 'Outfit', system-ui, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body.page-shop .wrap { max-width: 480px; margin: 0 auto; padding: var(--space-4); }
body.page-review .wrap,
body.page-drawings .wrap {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-4);
}

@media (min-width: 768px) {
  body.page-shop .wrap { max-width: min(720px, 96vw); }
}

@media (min-width: 900px) {
  body.page-shop .wrap { max-width: var(--page-max-shop); padding: var(--space-5); }
}

@media (min-width: 1024px) {
  body.page-review .wrap,
  body.page-drawings .wrap { padding: var(--space-6); }
}

/* Typography */
body.tom-production-ui h1 { font-size: 1.35rem; margin: 0; font-weight: 800; }
body.page-shop h1 { font-size: 1.25rem; margin: 0 0 var(--space-2); }
body.tom-production-ui .sub {
  color: var(--text-2);
  font-size: 0.9rem;
  margin: var(--space-1) 0 var(--space-4);
}
body.tom-production-ui a { color: var(--accent-deep); font-weight: 600; }

/* Shell */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.page-header--sticky {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  padding: var(--space-2) 0 var(--space-3);
  margin-bottom: var(--space-4);
}
.nav-cluster {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
}
a.nav-btn, button.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  width: auto;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
a.nav-btn:hover, button.nav-btn:hover { background: var(--border); }
a.nav-btn.active-page { background: var(--accent-deep); color: #fff; }
a.nav-btn.shop { background: var(--accent); color: #fff; }
a.nav-btn.shop:hover { background: var(--accent-deep); }
a.nav-btn.drawings { background: var(--accent); color: #fff; }
a.nav-btn.drawings:hover { background: var(--accent-deep); }
a.nav-btn.production { background: var(--text-2); color: #fff; }
a.nav-btn.production:hover { background: var(--text); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-shell);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.card--inset {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}
.pin-gate { max-width: 420px; margin: 0 auto; }
.section-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 var(--space-2);
  font-weight: 700;
}
.filter-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 var(--space-1);
}

/* Forms */
body.tom-production-ui label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: var(--space-1);
  font-weight: 600;
}
body.tom-production-ui input,
body.tom-production-ui select,
body.tom-production-ui textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text);
  width: 100%;
  margin-bottom: var(--space-2);
}
body.tom-production-ui button {
  background: var(--accent);
  color: #fff;
  border: none;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--radius-sm);
}
body.tom-production-ui button.secondary { background: var(--text-2); color: #fff; }
body.tom-production-ui button.danger { background: var(--danger); }
body.tom-production-ui button:disabled { opacity: 0.5; cursor: not-allowed; }
.hidden { display: none !important; }

/* Toast */
.toast {
  position: fixed;
  bottom: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  max-width: min(480px, calc(100vw - 32px));
  background: var(--text);
  color: #fff;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  text-align: center;
  z-index: 50;
}

/* Tab bar (scrollable dept tabs) */
.tab-bar-scroll {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: var(--space-1);
  margin-bottom: var(--space-3);
  max-width: 100%;
}
.tab-bar-scroll button {
  flex: 0 0 auto;
  margin: 0;
  white-space: nowrap;
  padding: var(--space-2) var(--space-3);
  font-size: 0.85rem;
}
.tab-bar-scroll button.active { background: var(--accent-deep); }
.tab-bar-scroll button.secondary { background: var(--text-2); }

/* Tables */
.data-table-wrap,
.table-wrap {
  overflow-x: auto;
  max-height: min(55vh, 560px);
  overflow-y: auto;
}
body.page-drawings .table-wrap { max-height: min(70vh, 720px); }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th, td {
  border: 1px solid var(--border);
  padding: var(--space-2);
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--surface-2);
  font-weight: 700;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
tr.on-hold { background: #fff7ed; }
tr.added-row { background: #eff6ff; }
tr.active-row { background: #ecfdf5; }
th.col-ot, td.col-ot { color: var(--danger); font-weight: 700; }
th.col-mfg, td.col-mfg { color: var(--green); font-weight: 700; }
th.col-hold, td.col-hold { color: var(--hold); font-weight: 700; }
.counts-bar { font-size: 0.82rem; color: var(--text-2); margin: 0 0 var(--space-2); }

.badge-status {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px var(--space-2);
  border-radius: 999px;
  background: var(--surface-2);
  margin-left: 6px;
}
.badge-status.added { background: #dbeafe; color: var(--info); }
.badge-status.active { background: #d1fae5; color: #047857; }
.badge-status.hold { background: #ffedd5; color: #c2410c; }

/* Production Review — dept grid */
.overview-toolbar {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.overview-toolbar h2 { margin: 0; font-size: 1.1rem; }

.employee-report-list,
.dept-layout {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
@media (min-width: 1200px) {
  .dept-layout {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-5);
    align-items: start;
  }
  .dept-layout > .employee-block--full,
  .dept-layout > .division-head-block,
  .dept-layout > .painter-note,
  .dept-layout > .trade-section-title,
  .dept-layout > .qc-panelists,
  .dept-layout > p {
    grid-column: 1 / -1;
  }
}

.employee-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-4);
}
@media (min-width: 1024px) {
  .employee-block { padding: var(--space-5); }
}
.employee-block.senior { border-left: 4px solid var(--accent-deep); }
.employee-block.flagged { border-left: 4px solid var(--danger); background: var(--surface-2); }
.employee-block--full { width: 100%; }

.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-3);
}
.client-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-3);
  cursor: pointer;
}
.client-card:hover,
.client-card.active {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(46, 42, 36, 0.1);
}
.client-card.flagged { border-color: var(--danger); background: var(--surface-2); }

/* Client master/detail (Production Review) */
.client-mode-layout {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
@media (min-width: 1100px) {
  .client-mode-layout.has-selection {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: var(--space-5);
    align-items: start;
  }
  .client-mode-layout.has-selection .client-mode-aside {
    max-height: min(75vh, 800px);
    overflow-y: auto;
  }
  .client-mode-layout.has-selection .report-panel {
    position: sticky;
    top: var(--header-sticky);
    max-height: min(75vh, 800px);
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
  }
  .client-mode-layout.has-selection .report-panel .data-table-wrap {
    flex: 1;
    min-height: 200px;
  }
}

.report-panel { margin-bottom: var(--space-4); }

.division-head-block {
  background: linear-gradient(135deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 2px solid var(--accent-deep);
  border-radius: 14px;
  padding: var(--space-5);
  margin-bottom: var(--space-2);
}
.emp-head-row { display: flex; gap: var(--space-3); align-items: center; margin-bottom: var(--space-2); }
.senior-badge {
  display: inline-block;
  font-size: 0.7rem;
  background: var(--accent-deep);
  color: #fff;
  padding: 2px var(--space-2);
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 700;
}
.division-badge {
  display: inline-block;
  font-size: 0.72rem;
  background: var(--text);
  color: var(--surface);
  padding: 3px 10px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 700;
  text-transform: uppercase;
}
.painter-note {
  background: var(--surface-2);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-card);
  padding: var(--space-3) var(--space-4);
  color: var(--text-2);
  margin-bottom: var(--space-3);
  font-size: 0.88rem;
}
.trade-section-title {
  font-size: 0.95rem;
  font-weight: 800;
  margin: var(--space-4) 0 var(--space-2);
  color: var(--text-2);
}

/* QC */
.qc-panelists {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  width: 100%;
}
@media (max-width: 720px) {
  .qc-panelists { grid-template-columns: 1fr; }
}
.qc-panelist-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-3) var(--space-4);
  display: flex;
  gap: var(--space-3);
  align-items: center;
  min-height: 88px;
}
.qc-list { display: flex; flex-direction: column; gap: var(--space-3); }
.qc-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-3);
}

/* All Drawings ops layout */
.ops-layout {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: minmax(240px, 300px) minmax(300px, 400px) minmax(0, 1fr);
  align-items: start;
}
@media (min-width: 1400px) {
  .ops-layout {
    gap: var(--space-5);
    grid-template-columns: minmax(260px, 320px) minmax(300px, 420px) minmax(0, 1fr);
  }
}
@media (max-width: 1100px) {
  .ops-layout { grid-template-columns: 1fr; }
  .ops-layout .detail-card { order: 2; }
  .ops-layout .table-card { order: 3; }
}
@media (min-width: 1101px) {
  .ops-layout .filters-card {
    position: sticky;
    top: var(--header-sticky);
    max-height: calc(100vh - var(--header-sticky) - 24px);
    overflow-y: auto;
  }
}
.carpenter-list {
  max-height: min(60vh, 520px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Shop-specific (linked when body.page-shop) */
body.page-shop .card { margin-bottom: var(--space-3); }
body.page-shop .card--inset {
  margin-top: var(--space-3);
  margin-bottom: 0;
}
body.page-shop .shop-work-grid { display: block; }
@media (min-width: 900px) {
  body.page-shop .shop-work-grid {
    display: grid;
    grid-template-columns: minmax(380px, 420px) 1fr;
    gap: var(--space-4);
    align-items: start;
  }
  body.page-shop .active-work-row { grid-column: 1 / -1; }
}
body.page-shop .shop-work-right {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  min-height: 0;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}
body.page-shop .active-work-row .finish-panel,
body.page-shop .active-work-row .new-drawing-box {
  min-height: auto;
}
body.page-shop .active-work-row.has-active-panel .finish-panel,
body.page-shop .active-work-row.has-active-panel .new-drawing-box {
  min-height: 280px;
}
body.page-shop #parked-jobs {
  flex: 1;
  min-height: 0;
  max-height: min(55vh, 560px);
  overflow-y: auto;
}
body.page-shop .head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); margin-bottom: var(--space-2); }
body.page-shop .head-row .head-title { display: flex; gap: var(--space-3); align-items: center; flex: 1; min-width: 0; }
body.page-shop .head-row .head-title h1 { margin: 0; }
body.page-shop .logo-img { height: 48px; width: auto; max-width: 110px; object-fit: contain; border-radius: var(--radius-sm); flex-shrink: 0; }

.admin-only.hidden-by-role { display: none !important; }
