/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
       background: #f4f3ef; color: #1a1a18; font-size: 14px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }
input, select { padding: 8px 10px; border: 1px solid #d4d2c9; border-radius: 7px;
                background: white; color: #1a1a18; width: 100%; outline: none; }
input:focus, select:focus { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.12); }

/* ── Buttons ───────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center;
       padding: 8px 16px; border-radius: 7px; border: 1px solid #d4d2c9;
       cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap;
       transition: background .15s, border-color .15s; }
.btn-primary   { background: #2563eb; color: white; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-secondary { background: white; color: #374151; }
.btn-secondary:hover { background: #f1efe8; }
.btn-success   { background: #166534; color: white; border-color: #166534; }
.btn-success:hover { background: #14532d; }
.btn-warning   { background: #92400e; color: white; border-color: #92400e; }
.btn-warning:hover { background: #78350f; }
.btn-block     { width: 100%; }
.btn:disabled  { opacity: 0.5; cursor: not-allowed; }
.btn-icon      { background: none; border: none; cursor: pointer; color: #6b7280;
                 font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.btn-icon:hover { background: #fee2e2; color: #991b1b; }
.btn-danger-sm { background: white; border: 1px solid #fca5a5; color: #991b1b;
                 padding: 4px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-danger-sm:hover { background: #fee2e2; }

/* ── Status Tags ───────────────────────────────────────── */
.tag { display: inline-block; padding: 2px 8px; border-radius: 5px;
       font-size: 10px; font-weight: 600; letter-spacing: .03em; }
.tag-done    { background: #dcfce7; color: #166534; }
.tag-wip     { background: #fef3c7; color: #92400e; }
.tag-open    { background: #dbeafe; color: #1e40af; }
.tag-waiting { background: #f3f4f6; color: #6b7280; }
.tag-hold    { background: #fee2e2; color: #991b1b; }

/* ── Alerts ────────────────────────────────────────────── */
.alert { padding: 9px 13px; border-radius: 7px; font-size: 13px; margin-top: 8px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-ok    { background: #dcfce7; color: #166534; }
.alert-info  { background: #eff6ff; color: #1d4ed8; }

/* ── Auth page ─────────────────────────────────────────── */
.auth-page { background: #f4f3ef; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-box { background: white; border-radius: 12px; padding: 32px; width: 380px;
            box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06); }
.auth-logo h1 { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.auth-logo p  { font-size: 13px; color: #6b7280; margin-bottom: 20px; }

/* ── Topbar ────────────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 40; background: white;
          border-bottom: 1px solid #e5e3db; padding: 0 24px; height: 56px;
          display: flex; align-items: center; justify-content: space-between; }
.topbar-left  { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-title { font-size: 15px; font-weight: 600; color: #1a1a18; }
.topbar-user  { font-size: 13px; color: #6b7280; margin-left: 8px; }
.logout-link  { color: #2563eb; margin-left: 6px; font-size: 12px; }
.logout-link:hover { text-decoration: underline; }

/* ── Role badges ───────────────────────────────────────── */
.role-badge { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.role-admin { background: #ede9fe; color: #5b21b6; }
.role-lead  { background: #dbeafe; color: #1e40af; }
.role-user  { background: #f3f4f6; color: #374151; }
.you-badge  { font-size: 10px; color: #6b7280; margin-left: 4px; }

/* ── Main content ──────────────────────────────────────── */
.main-content { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.page-header  { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-header h2 { font-size: 18px; font-weight: 600; }
.count-badge  { background: #f3f4f6; color: #374151; font-size: 12px;
                padding: 2px 10px; border-radius: 10px; }

/* ── Production table ──────────────────────────────────── */
.table-wrap { overflow: auto; border-radius: 10px;
              /* Bounded height turns this into its own scroll area, which is
                 what lets the header row freeze while the rows scroll under it. */
              max-height: calc(100vh - 160px);
              box-shadow: 0 1px 3px rgba(0,0,0,.07), 0 2px 8px rgba(0,0,0,.05); }

/* Frozen column headers on the production board */
.prod-table thead th { position: -webkit-sticky; position: sticky; top: 0; z-index: 3;
                       background: #f9f8f5;
                       box-shadow: 0 1px 0 #e5e3db; }
/* The top-left corner cell freezes in BOTH directions, so it must sit above
   both the frozen header row and the frozen product column. */
.prod-table thead .sticky-col { z-index: 6; }
.prod-table tbody .sticky-col { z-index: 2; }

/* Group heading rows (product type) stick just under the header row, so you
   always know which group you're looking at. Remove this block if the offset
   ever looks off. */
.prod-table tbody tr.group-header > td { position: -webkit-sticky; position: sticky;
                                         top: 35px; z-index: 4; background: #f4f2ec; }
.prod-table { width: 100%; border-collapse: collapse; background: white;
              min-width: 900px; }
.prod-table thead tr { background: #f9f8f5; border-bottom: 1px solid #e5e3db; }
.prod-table th { padding: 10px 12px; font-size: 11px; font-weight: 600;
                 color: #6b7280; text-align: left; white-space: nowrap; }
.prod-table td { border-top: 1px solid #f0ede6; vertical-align: top; }
.prod-table tbody tr:hover { background: #fdfcfa; }

.sticky-col { position: sticky; left: 0; background: white; z-index: 2;
              box-shadow: 2px 0 4px rgba(0,0,0,.06); min-width: 120px; }
.prod-table thead .sticky-col { background: #f9f8f5; }

.stage-cell { padding: 10px 12px; cursor: pointer; min-width: 130px;
              transition: background .1s; }
.stage-cell:hover { background: #f0f4ff; }
.cell-blocked { opacity: 0.55; cursor: default; }
.cell-blocked:hover { background: inherit; }
.cell-over { }

.col-product { padding: 10px 12px; }
.product-id  { font-weight: 600; font-size: 13px; }
.product-ref { font-size: 11px; color: #9ca3af; margin-top: 2px; }
.stage-hours { font-size: 11px; color: #6b7280; margin-top: 3px; }
.hours-over  { color: #dc2626; font-weight: 500; }
.warn-icon   { color: #dc2626; font-size: 11px; }
.stage-owner { font-size: 10px; color: #9ca3af; margin-top: 2px; }

.empty-state { text-align: center; padding: 48px 20px; color: #9ca3af; }

/* ── Modals ────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4);
                 display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box     { background: white; border-radius: 12px; width: 480px; max-width: 95vw;
                 max-height: 88vh; overflow-y: auto;
                 box-shadow: 0 8px 32px rgba(0,0,0,.18); }
.modal-box-lg  { width: 580px; }
.modal-header  { display: flex; justify-content: space-between; align-items: flex-start;
                 padding: 18px 20px 12px; border-bottom: 1px solid #f0ede6; }
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close   { background: none; border: none; font-size: 16px; cursor: pointer;
                 color: #9ca3af; padding: 0 4px; line-height: 1; }
.modal-close:hover { color: #374151; }
.modal-body    { padding: 18px 20px; }
.modal-footer  { padding: 12px 20px 18px; display: flex; gap: 8px; justify-content: flex-end;
                 border-top: 1px solid #f0ede6; }
.loading       { padding: 32px; text-align: center; color: #9ca3af; }

/* ── Progress bar ──────────────────────────────────────── */
.progress-header { display: flex; justify-content: space-between;
                   font-size: 13px; margin-bottom: 6px; }
.progress-bar    { height: 7px; background: #f0ede6; border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
.progress-fill   { height: 100%; border-radius: 4px; transition: width .3s; }
.fill-accent  { background: #2563eb; }
.fill-danger  { background: #dc2626; }
.text-danger  { color: #dc2626; font-weight: 500; }
.text-ok      { color: #166534; }

/* ── Stage detail elements ─────────────────────────────── */
.owner-line  { font-size: 12px; color: #6b7280; margin-left: 8px; }
.action-row  { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.owner-change { margin-bottom: 14px; padding: 10px 12px; background: #f9f8f5; border-radius: 8px; }
.owner-change label { font-size: 12px; color: #6b7280; display: block; margin-bottom: 6px; }
.section-label { font-size: 11px; font-weight: 600; color: #9ca3af; letter-spacing: .05em;
                 text-transform: uppercase; margin-bottom: 8px; margin-top: 4px; }
.log-form  { margin-top: 12px; padding-top: 12px; border-top: 1px solid #f0ede6; }

/* ── Log table ─────────────────────────────────────────── */
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th { text-align: left; padding: 5px 6px; font-size: 11px; color: #9ca3af;
                font-weight: 500; border-bottom: 1px solid #f0ede6; }
.log-table td { padding: 6px 6px; border-bottom: 1px solid #f9f8f5; }
.empty-row { color: #9ca3af; padding: 12px 6px; }

/* ── Forms ─────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.form-group label { font-size: 12px; font-weight: 500; color: #374151; }
.form-row   { display: flex; gap: 10px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 120px; }
.required   { color: #dc2626; }

/* ── Tabs ──────────────────────────────────────────────── */
.tab-bar  { display: flex; gap: 4px; border-bottom: 1px solid #e5e3db; margin-bottom: 20px; }
.tab-link { padding: 8px 16px; font-size: 13px; color: #6b7280; border-bottom: 2px solid transparent;
            margin-bottom: -1px; transition: color .15s; }
.tab-link:hover { color: #374151; }
.tab-link.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 500; }
.tab-content { }

/* ── Cards ─────────────────────────────────────────────── */
.card { background: white; border-radius: 10px; padding: 16px 18px;
        box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card-header { font-size: 14px; margin-bottom: 12px; padding-bottom: 10px;
               border-bottom: 1px solid #f0ede6; }

/* ── Data tables ───────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px;
              background: white; border-radius: 10px; overflow: hidden;
              box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.data-table th { padding: 10px 12px; font-size: 11px; font-weight: 600; color: #6b7280;
                 text-align: left; background: #f9f8f5; border-bottom: 1px solid #e5e3db; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid #f4f3ef; vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fdfcfa; }
.row-over td  { background: #fff7f7; }
.row-over:hover td { background: #fee2e2; }

/* ── Owner grid in manage ──────────────────────────────── */
.owner-grid  { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px; }
.owner-item  { display: flex; flex-direction: column; gap: 3px; }
.owner-stage { font-size: 10px; color: #9ca3af; font-weight: 500; }
.owner-select { font-size: 12px; padding: 4px 6px; height: 30px; }

/* ── Target grid ───────────────────────────────────────── */
.target-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.target-input { height: 36px; }

/* ── Stage edit ────────────────────────────────────────── */
.stage-edit-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.stage-num      { font-size: 12px; color: #9ca3af; width: 20px; flex-shrink: 0; }
.stage-name-input { flex: 1; height: 36px; }

/* ── Status dots ───────────────────────────────────────── */
.status-dot      { font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.dot-active      { background: #dcfce7; color: #166534; }
.dot-inactive    { background: #f3f4f6; color: #6b7280; }

/* ── Accountability ────────────────────────────────────── */
.section-header  { margin-bottom: 10px; }
.section-header h3 { font-size: 15px; font-weight: 600; }
.alert-dot { font-size: 11px; color: #dc2626; background: #fee2e2;
             padding: 2px 8px; border-radius: 10px; margin-left: 8px; }

/* ── Misc ──────────────────────────────────────────────── */
.text-muted { color: #9ca3af; font-size: 13px; }
.role-select { width: auto; height: 30px; font-size: 12px; padding: 2px 6px; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 640px) {
    .table-wrap { max-height: calc(100vh - 110px); }
    .topbar { padding: 8px 14px; height: auto; flex-wrap: wrap; gap: 8px; }
    .topbar-title { font-size: 13px; }
    .topbar-left { width: 100%; }
    .topbar-right { width: 100%; flex-wrap: wrap; gap: 6px; }
    .topbar-right .btn { display: inline-flex; padding: 6px 10px; font-size: 12px; }
    .topbar-user { width: 100%; margin-left: 0; }
    .main-content { padding: 16px 12px 48px; }
    .modal-box { width: 100%; max-width: 100%; height: 100%; max-height: 100%;
                 border-radius: 0; margin: 0; }
    .form-row { flex-direction: column; }
    .action-row { flex-direction: column; }
}

/* Stage popup tabs — here rather than in the injected HTML, so the rules exist
   before the popup opens instead of being re-inserted on every open. */
.sd-tab{padding:7px 13px;border:0;border-bottom:2px solid transparent;background:none;
  font-size:13px;font-weight:600;color:#6b7280;cursor:pointer}
.sd-tab.on{color:#3730a3;border-bottom-color:#3730a3}
.sd-tab:hover{color:#374151}
.sd-n{background:#6b7280;color:#fff;font-size:10px;font-weight:800;padding:0 5px;border-radius:8px}
.sd-pane{display:none}
.sd-pane.on{display:block}
/* One height for every pane, so switching tabs does not make the popup jump.
   Long panes scroll inside instead of stretching the dialog. */
.sd-panes{min-height:340px;max-height:56vh;overflow-y:auto}
