/* Paper Timesheet Audit UI — Bowser AI brand */
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@300;400;500;600;700&display=swap');

:root {
  --shadow-grey: #2D232E;
  --gunmetal: #474448;
  --taupe-grey: #534B52;
  --accent: #8C7051;
  --amber: #FFAB40;
  --bone: #E0DDCF;
  --parchment: #F1F0EA;
  --text: #2D232E;
  --font-size: 11px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Raleway", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--parchment);
  color: var(--text);
  font-size: var(--font-size);
}

/* ===== SUMMARY BAR — Bowser brand ===== */
.summary-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--shadow-grey);
  color: var(--parchment);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  font-family: "Raleway", "Helvetica Neue", sans-serif;
}
.summary-bar .brand {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--amber);
  white-space: nowrap;
}
.summary-bar h1 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--parchment);
  border-left: 2px solid var(--accent);
  padding-left: 12px;
  margin-left: 4px;
}
.stats { display: flex; gap: 12px; align-items: center; }
.stat { background: rgba(255,255,255,0.08); padding: 3px 10px; border-radius: 3px; font-size: 12px; }
.stat-good { background: rgba(34,197,94,0.2); color: #86efac; }
.stat-warn { background: rgba(234,179,8,0.2); color: #fde68a; }
.stat-meta { font-size: 10px; opacity: 0.5; margin-left: auto; }
.no-data { opacity: 0.7; }
.no-data code { background: rgba(255,255,255,0.15); padding: 2px 6px; border-radius: 3px; }

/* Mode control dropdown */
.mode-control {
  display: flex; align-items: center; gap: 4px;
  font-size: 10px; color: var(--bone); margin-left: 8px;
}
.mode-control label {
  font-weight: 600; font-size: 10px;
  font-family: "Raleway", sans-serif;
}
.mode-control select {
  padding: 1px 6px; border: 1px solid var(--taupe-grey);
  background: var(--gunmetal); color: var(--bone);
  border-radius: 3px; cursor: pointer; font-size: 10px;
  font-family: "Raleway", sans-serif;
}
.mode-control select:hover { background: var(--accent); color: var(--parchment); }

/* Font size control */
/* Export link */
.export-btn {
  padding: 2px 10px; border: 1px solid var(--amber);
  background: transparent; color: var(--amber); border-radius: 3px;
  font-size: 10px; font-weight: 600; cursor: pointer;
  font-family: "Raleway", sans-serif; text-decoration: none;
  margin-left: auto;
}
.export-btn:hover { background: var(--amber); color: var(--shadow-grey); }

.font-size-control {
  display: flex; align-items: center; gap: 4px;
  font-size: 10px; color: var(--bone);
  margin-left: 8px;
}
.font-size-control button {
  width: 20px; height: 20px; border: 1px solid var(--taupe-grey);
  background: var(--gunmetal); color: var(--bone);
  border-radius: 3px; cursor: pointer; font-size: 12px;
  font-weight: 700; line-height: 1; display: flex;
  align-items: center; justify-content: center;
}
.font-size-control button:hover { background: var(--accent); color: var(--parchment); }
.font-size-control span { min-width: 28px; text-align: center; }

/* ===== SHEET CARDS ===== */
main { padding: 12px; }

.sheet-card {
  background: #fff;
  border: 1px solid #bbb;
  margin-bottom: 20px;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.1);
}

.sheet-header {
  background: var(--bone);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 3px solid var(--accent);
  font-family: "Raleway", "Helvetica Neue", sans-serif;
  font-size: 11px;
  flex-wrap: wrap;
}
.sheet-header h2 { font-size: calc(var(--font-size) + 2px); font-weight: 700; color: var(--shadow-grey); }

.tag {
  font-size: 10px; padding: 1px 6px; border-radius: 2px;
  background: #ccc8c0; color: var(--shadow-grey);
}
.tag-quality-high { background: #d1fae5; color: #065f46; }
.tag-quality-medium { background: #fef3c7; color: #92400e; }
.tag-quality-low { background: #fecaca; color: #991b1b; }

/* Loupe toggle */
.loupe-toggle {
  padding: 1px 6px; border: 1px solid #aaa; background: #fff;
  font-size: 9px; cursor: pointer; border-radius: 2px;
  color: #555; font-weight: 500; margin-left: 4px;
  font-family: "Raleway", sans-serif;
}
.loupe-toggle.active { background: var(--accent); color: var(--parchment); border-color: var(--accent); }

/* Review controls */
.error-checkbox {
  display: flex; align-items: center; gap: 3px;
  font-weight: 600; color: #dc2626; cursor: pointer; margin-left: auto;
  font-family: "Raleway", sans-serif;
}
.error-checkbox input[type="checkbox"] { width: 14px; height: 14px; accent-color: #dc2626; }

.notes-input {
  width: 200px; padding: 2px 6px; border: 1px solid #bbb; border-radius: 3px;
  font-size: 11px; font-family: "Raleway", sans-serif;
}
.notes-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(140,112,81,0.25); }

/* ===== SIDE-BY-SIDE LAYOUT — no per-section scrolling ===== */
.sheet-body {
  display: flex;
}

.image-panel {
  background: #f5f5f0;
  flex: 0 0 40%;
  position: relative;
  overflow: hidden;
}
.image-panel img { width: 100%; display: block; }

/* Loupe lens */
.loupe-lens {
  display: none;
  position: absolute;
  width: 180px; height: 180px;
  border: 2px solid var(--shadow-grey);
  border-radius: 50%;
  pointer-events: none;
  z-index: 10;
  background-repeat: no-repeat;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

/* Resize handle */
.resize-handle {
  width: 6px; cursor: col-resize;
  background: var(--accent);
  flex-shrink: 0; position: relative; z-index: 5;
  opacity: 0.5;
}
.resize-handle:hover, .resize-handle.dragging { opacity: 1; }

.data-panel {
  padding: 4px;
  flex: 1 1 auto;
  min-width: 200px;
  overflow-x: auto;
}

/* Metadata tags bar — inside data panel (Gemini-interpreted) */
.data-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 2px 6px;
  border-bottom: 1px solid #ddd;
  margin-bottom: 4px;
}

/* ===== TIMESHEET TABLE ===== */

.ts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size);
  border: 2px solid var(--shadow-grey);
  table-layout: auto;
}

.ts-table th,
.ts-table td {
  border: 1px solid #aaa;
  padding: 2px 3px;
  text-align: center;
  white-space: nowrap;
  height: 20px;
}

/* Phase code header — rotated 90deg with wrap on dashes */
.phase-code-row th.col-phase {
  border: 2px solid var(--shadow-grey);
  background: var(--bone);
  font-size: calc(var(--font-size) - 2px);
  font-weight: 700;
  letter-spacing: -0.3px;
  padding: 3px 2px;
  width: 24px;
  min-width: 24px;
  height: auto;
  min-height: 120px;
  vertical-align: bottom;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  white-space: nowrap;
  overflow: hidden;
  line-height: 1.2;
}
/* Allow wrapping only at inserted <wbr> points */
.phase-code-row th.col-phase wbr { display: inline; }
.phase-code-row th.col-phase { white-space: normal; word-break: keep-all; overflow-wrap: normal; }

/* Trade column */
.col-trade-class {
  width: 28px; min-width: 28px; max-width: 36px;
  font-size: 9px; font-weight: 600; color: var(--taupe-grey);
  text-align: center !important;
}
thead .col-trade-class {
  background: var(--bone); border: 2px solid var(--shadow-grey);
  font-size: calc(var(--font-size) - 2px);
}

/* Name column */
.col-name {
  text-align: left !important;
  min-width: 100px; max-width: 150px;
  font-weight: 600;
  padding-left: 4px !important;
  white-space: normal !important;
}
thead .col-name {
  background: var(--bone); border: 2px solid var(--shadow-grey);
  font-size: calc(var(--font-size) - 1px);
}

/* Earn code column */
.col-earn-code {
  width: 22px; min-width: 22px; max-width: 28px;
  font-size: calc(var(--font-size) - 3px); font-weight: 600; color: var(--taupe-grey);
  text-align: center !important;
  padding: 0 1px !important;
  border-right: 2px solid var(--shadow-grey) !important;
}
thead .col-earn-code { background: var(--bone); border: 2px solid var(--shadow-grey); }

/* Worker row grouping */
.worker-row-st td { border-top: 2px solid var(--gunmetal); }
.worker-row-ot td, .worker-row-dt td { border-top: 1px solid #ddd; }

/* Hours cells */
.col-hours {
  width: 28px; min-width: 22px;
  font-variant-numeric: tabular-nums;
}

/* Total / Notes / Travel */
.col-total {
  width: 34px; font-weight: 700;
  border-left: 2px solid var(--shadow-grey) !important;
  border-right: 1px solid #aaa;
}
.col-paid {
  width: 34px; font-weight: 700;
  border-left: 1px solid #aaa;
}
.col-notes { text-align: left !important; min-width: 30px; font-size: calc(var(--font-size) - 1px); }
.col-travel { width: 38px; border-right: 2px solid var(--shadow-grey) !important; }

/* Confidence highlighting */
.confidence-high { background-color: #ecfdf5 !important; }
.confidence-medium { background-color: #fefce8 !important; }
.confidence-low { background-color: #fef2f2 !important; }

/* Hour mismatch highlighting */
.hours-row-mismatch { background-color: #fdba74 !important; }
.hours-col-mismatch { background-color: #fde68a !important; }
.hours-both-mismatch { background-color: #fb923c !important; }
.hours-over-limit { background-color: #fecaca !important; }

/* Clickable cells */
.ts-table td { cursor: pointer; }
.ts-table td:hover { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Absence rows */
.row-absent { background: #f9fafb; }
.row-absent .col-name { color: #9ca3af; }
.absence-cell {
  text-align: center; vertical-align: middle; color: #9ca3af;
  font-style: italic; font-size: 10px; letter-spacing: 1px;
}

/* Totals */
.totals-row { background: var(--bone) !important; border-top: 2px solid var(--shadow-grey); }
.totals-row td { font-weight: 700; }

/* Flags */
.flags {
  margin-top: 4px; padding: 3px 6px;
  background: #fffbeb; border: 1px solid #fcd34d;
  border-radius: 2px; font-size: 10px;
}
.flag-item { color: #92400e; padding: 1px 0; }
.flag-item::before { content: "! "; font-weight: 700; }

/* ===== CELL EDIT POPUP ===== */
.cell-edit-overlay {
  display: none; position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3); z-index: 200;
}
.cell-edit-overlay.visible { display: flex; align-items: center; justify-content: center; }

.cell-edit-popup {
  background: #fff; border: 2px solid var(--shadow-grey); border-radius: 6px;
  padding: 16px; width: 360px; max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  font-family: "Raleway", sans-serif;
}
.cell-edit-popup h3 { font-size: 13px; margin-bottom: 10px; color: var(--shadow-grey); }
.cell-edit-popup label {
  display: block; font-size: 11px; font-weight: 600;
  color: #555; margin-bottom: 3px; margin-top: 8px;
}
.cell-edit-popup input[type="text"],
.cell-edit-popup textarea {
  width: 100%; padding: 5px 8px; border: 1px solid #bbb;
  border-radius: 3px; font-size: 12px;
  font-family: "SF Mono", Monaco, Consolas, monospace;
}
.cell-edit-popup textarea { height: 50px; resize: vertical; }
.cell-edit-popup input[type="text"]:focus,
.cell-edit-popup textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(140,112,81,0.25);
}
.cell-edit-actions { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }
.cell-edit-actions button {
  padding: 4px 14px; border-radius: 3px; font-size: 11px;
  font-weight: 600; cursor: pointer; border: 1px solid #aaa;
}
.btn-save { background: var(--shadow-grey); color: var(--parchment); border-color: var(--shadow-grey); }
.btn-save:hover { background: var(--gunmetal); }
.btn-cancel { background: #fff; color: #555; }
.btn-cancel:hover { background: #f0f0f0; }
.cell-edit-path { font-size: 9px; color: #999; margin-top: 2px; font-family: "SF Mono", Monaco, Consolas, monospace; }

/* Edit history in cell popup */
.cell-edit-history {
  margin-top: 10px; padding-top: 8px; border-top: 1px solid #ddd;
}
.cell-edit-history:empty { display: none; }
.edit-history-label { font-size: 10px; font-weight: 600; color: #888; margin-bottom: 4px; }
.edit-history-item { font-size: 10px; color: #666; padding: 2px 0; }
.edit-history-value { font-weight: 600; font-family: "SF Mono", Monaco, Consolas, monospace; }
.edit-history-reason { font-style: italic; color: #999; }
.edit-history-time { color: #bbb; font-size: 9px; }

/* ===== PHASE CODE VALIDATION COLORS ===== */
.phase-exact  { background-color: #065f46 !important; color: #ecfdf5 !important; }
.phase-high   { background-color: #d1fae5 !important; color: #065f46 !important; }
.phase-medium { background-color: #fefce8 !important; color: #92400e !important; }
.phase-low    { background-color: #fef2f2 !important; color: #991b1b !important; }

/* Clickable phase headers */
.phase-code-row th.col-phase.phase-clickable { cursor: pointer; }
.phase-code-row th.col-phase.phase-clickable:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.phase-code-row th.col-phase.phase-exact.phase-clickable:hover { outline-color: #86efac; }

/* ===== PHASE SUGGESTION POPUP ===== */
.phase-suggest-overlay {
  display: none; position: fixed;
  top: 0; left: 50%; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3); z-index: 200;
}
.phase-suggest-overlay.visible { display: flex; align-items: center; justify-content: center; }

.phase-suggest-popup {
  background: #fff; border: 2px solid var(--shadow-grey); border-radius: 6px;
  padding: 16px; width: 520px; max-width: 90vw; max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  font-family: "Raleway", sans-serif;
}
.phase-suggest-popup h3 { font-size: 13px; margin-bottom: 4px; color: var(--shadow-grey); }
.phase-suggest-meta { font-size: 10px; color: #888; margin-bottom: 12px; }

.phase-suggest-current {
  background: #f5f5f0; padding: 8px 10px; border-radius: 4px;
  margin-bottom: 12px; font-size: 11px;
}
.phase-suggest-current strong { font-size: 12px; }
.phase-suggest-reasoning { font-size: 10px; color: #666; margin-top: 4px; font-style: italic; }

.phase-suggest-list { list-style: none; }
.suggest-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border: 1px solid #ddd; border-radius: 4px;
  margin-bottom: 6px; font-size: 11px;
}
.suggest-item:hover { background: #f9f9f5; border-color: var(--accent); }
.suggest-item-info { flex: 1; }
.suggest-item-code { font-weight: 700; font-family: "SF Mono", Monaco, Consolas, monospace; }
.suggest-item-desc { font-size: 10px; color: #666; }
.suggest-item-reason { font-size: 9px; color: #999; font-style: italic; }

.suggest-select-btn {
  padding: 3px 10px; border: 1px solid var(--accent); border-radius: 3px;
  background: #fff; color: var(--accent); font-size: 10px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.suggest-select-btn:hover { background: var(--accent); color: var(--parchment); }

/* Manual phase code entry */
.phase-manual-entry {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid #ddd;
}
.phase-manual-entry label {
  display: block; font-size: 11px; font-weight: 600;
  color: #555; margin-bottom: 4px;
}
.phase-manual-row {
  display: flex; gap: 6px; align-items: center;
}
.phase-manual-row input[type="text"] {
  flex: 1; padding: 5px 8px; border: 1px solid #bbb;
  border-radius: 3px; font-size: 12px;
  font-family: "SF Mono", Monaco, Consolas, monospace;
}
.phase-manual-row input[type="text"]:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(140,112,81,0.25);
}

.phase-suggest-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.phase-suggest-actions button {
  padding: 4px 14px; border-radius: 3px; font-size: 11px;
  font-weight: 600; cursor: pointer; border: 1px solid #aaa;
  background: #fff; color: #555;
}
.phase-suggest-actions button:hover { background: #f0f0f0; }

/* Responsive */
@media (max-width: 1000px) {
  .sheet-body { flex-direction: column; }
  .image-panel { flex: none; max-height: 400px; overflow: auto; }
  .resize-handle { display: none; }
}

/* ===== AUTH UI ===== */
.login-screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--parchment);
  z-index: 300;
}

.login-box {
  background: #fff;
  border: 2px solid var(--shadow-grey);
  border-radius: 8px;
  padding: 40px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  font-family: "Raleway", sans-serif;
  max-width: 400px;
  width: 90%;
}

.login-brand {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--amber);
  display: block;
  margin-bottom: 8px;
}

.login-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--shadow-grey);
  margin-bottom: 24px;
}

.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  background: var(--shadow-grey);
  color: var(--parchment);
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: "Raleway", sans-serif;
}
.login-btn:hover { background: var(--gunmetal); }

.login-error {
  color: #dc2626;
  font-size: 12px;
  margin-top: 12px;
}

.login-loading {
  color: var(--taupe-grey);
  font-size: 12px;
  margin-top: 12px;
}

/* Sign out button in header */
.signout-btn {
  padding: 2px 8px;
  border: 1px solid var(--taupe-grey);
  background: transparent;
  color: var(--bone);
  border-radius: 3px;
  font-size: 9px;
  cursor: pointer;
  font-family: "Raleway", sans-serif;
  margin-left: auto;
}
.signout-btn:hover { background: rgba(255,255,255,0.1); }
