/* -----------------------------------------------------------------------
   Base
----------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --cnc1: #CDAB4A;
  --cnc1-light: #faf5e8;
  --cnc1-border: #e8d9a0;
  --cnc2: #807161;
  --cnc2-light: #f5f1ee;
  --cnc2-border: #c9b8ae;
  --bg: #F7F4F2;
  --surface: #ffffff;
  --border: #E2DCD5;
  --text: #2E2E2E;
  --muted: #807161;
  --danger: #dc2626;
  --today-border: #CDAB4A;
  --today-bg: #faf5e8;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --radius: 6px;
}

html, body { height: 100%; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

a { color: inherit; text-decoration: none; }

/* -----------------------------------------------------------------------
   Header
----------------------------------------------------------------------- */
.app-header {
  background: #2E2E2E;
  border-bottom: 1px solid #3d3d3d;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  gap: 12px;
  color: #F7F4F2;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-logo {
  width: 36px; height: 36px; border-radius: 6px;
  background: #CDAB4A; color: #2E2E2E; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.header-title { font-size: 16px; font-weight: 700; white-space: nowrap; color: #F7F4F2; }
.header-updated { font-size: 11px; color: rgba(247,244,242,.6); }
.header-right { display: flex; align-items: center; gap: 8px; }
.app-header .btn-ghost { color: rgba(247,244,242,.75); }
.app-header .btn-ghost:hover { color: #F7F4F2; background: rgba(255,255,255,.1); }
.app-header .btn-outline { color: #F7F4F2; border-color: rgba(247,244,242,.3); }
.app-header .btn-outline:hover { background: rgba(255,255,255,.1); }

/* -----------------------------------------------------------------------
   Buttons
----------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px; border-radius: var(--radius); border: 1px solid transparent;
  font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--cnc1); color: #2E2E2E; border-color: var(--cnc1); }
.btn-primary:hover { background: #b8963e; border-color: #b8963e; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--bg); }
.btn-full { width: 100%; justify-content: center; }

/* -----------------------------------------------------------------------
   Tabs
----------------------------------------------------------------------- */
.tab-nav {
  display: flex; gap: 0; background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  overflow-x: auto;
}
.tab-btn {
  padding: 12px 18px; border: none; background: none;
  font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--cnc1); border-bottom-color: var(--cnc1); }

/* -----------------------------------------------------------------------
   Main content
----------------------------------------------------------------------- */
.app-main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.tab-content { display: block; }
.card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow); padding: 16px;
}

/* -----------------------------------------------------------------------
   Settings panel
----------------------------------------------------------------------- */
.settings-panel { margin-bottom: 16px; }
.settings-title { font-weight: 600; font-size: 13px; margin-bottom: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.settings-row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.settings-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.settings-input {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; width: 120px; background: var(--bg);
}
.settings-input:focus { outline: none; border-color: var(--cnc1); }
.settings-saved { font-size: 12px; color: var(--cnc2); font-weight: 600; opacity: 0; transition: opacity .3s; }
.settings-saved.show { opacity: 1; }

.total-chips-divider {
  width: 1px; align-self: stretch;
  background: var(--border); margin: 0 4px; flex-shrink: 0;
}
.total-chip {
  display: flex; flex-direction: column; gap: 1px;
  padding: 8px 14px 8px 12px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--surface);
  min-width: 110px;
  align-self: stretch;
  justify-content: center;
}
.cnc1-chip { border-left-color: var(--cnc1); }
.cnc2-chip { border-left-color: var(--cnc2); }
.total-chip-machine {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.total-chip-count {
  font-size: 28px; font-weight: 800; line-height: 1.1;
}
.cnc1-chip .total-chip-count { color: var(--cnc1); }
.cnc2-chip .total-chip-count { color: var(--cnc2); }
.total-chip-label { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* -----------------------------------------------------------------------
   Columns
----------------------------------------------------------------------- */
.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.column { display: flex; flex-direction: column; gap: 0; }

.col-header {
  font-size: 15px; font-weight: 700; padding: 12px 16px;
  border-radius: var(--radius) var(--radius) 0 0;
  letter-spacing: .03em;
}
.cnc1-header { background: var(--cnc1); color: #2E2E2E; }
.cnc2-header { background: var(--cnc2); color: #fff; }

/* -----------------------------------------------------------------------
   Capacity bar
----------------------------------------------------------------------- */
.capacity-bar {
  background: var(--surface); border: 1px solid var(--border); border-top: none;
  padding: 10px 14px; font-size: 12px; color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 12px;
}
.cap-stat { display: flex; gap: 5px; align-items: center; }
.cap-label { color: var(--muted); }
.cap-value { font-weight: 600; color: var(--text); }

/* -----------------------------------------------------------------------
   Day cards
----------------------------------------------------------------------- */
.day-card {
  background: var(--surface); border: 1px solid var(--border); border-top: none;
  padding: 0;
}
.day-card:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.day-card.today { border-left: 3px solid var(--today-border); background: var(--today-bg); }
.day-card.past { opacity: .6; }
.day-card.empty-col { border-radius: 0 0 var(--radius) var(--radius); padding: 24px 16px; text-align: center; color: var(--muted); font-style: italic; }

.day-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  background: rgba(0,0,0,.02);
}
.day-header .today-badge {
  background: var(--today-border); color: #fff; font-size: 10px;
  padding: 2px 6px; border-radius: 99px; font-weight: 700;
}
.day-total { font-size: 11px; color: var(--muted); }

.job-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.job-row:last-of-type { border-bottom: none; }
.job-row.done { color: var(--muted); }
.job-name { flex: 1; }
.job-sheets {
  font-size: 12px; font-weight: 600; padding: 2px 8px;
  border-radius: 99px; background: var(--bg); color: var(--muted);
  white-space: nowrap;
}
.job-done-mark { margin-right: 6px; color: var(--cnc2); font-weight: 700; }
.day-footer {
  padding: 8px 14px; font-weight: 700; font-size: 12px;
  border-top: 1px solid var(--border); background: rgba(0,0,0,.02);
  text-align: right;
}

/* -----------------------------------------------------------------------
   Report controls
----------------------------------------------------------------------- */
.report-controls { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.ctrl-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ctrl-input {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; background: var(--bg);
}
.ctrl-input:focus { outline: none; border-color: var(--cnc1); }

/* -----------------------------------------------------------------------
   Report table
----------------------------------------------------------------------- */
.table-card { padding: 0; overflow: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th, .report-table td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.report-table th { font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; background: var(--bg); }
.report-table tfoot td { font-weight: 700; background: var(--bg); }
.cnc1-text { color: var(--cnc1); }
.cnc2-text { color: var(--cnc2); }

/* -----------------------------------------------------------------------
   Charts
----------------------------------------------------------------------- */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-section { }
.chart-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.chart-total { font-size: 13px; color: var(--muted); margin-top: 10px; font-weight: 600; }

.no-data { padding: 24px 16px; text-align: center; color: var(--muted); font-style: italic; font-size: 13px; }

/* -----------------------------------------------------------------------
   Spinners / Errors
----------------------------------------------------------------------- */
.spinner-wrap { display: flex; justify-content: center; padding: 40px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--cnc1);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-msg { color: var(--danger); font-size: 13px; padding: 10px 0; }

/* -----------------------------------------------------------------------
   Login
----------------------------------------------------------------------- */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08); padding: 40px; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.login-logo {
  width: 52px; height: 52px; border-radius: 10px; background: #2E2E2E;
  color: #CDAB4A; font-weight: 800; font-size: 18px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 4px;
}
.login-card h1 { font-size: 20px; font-weight: 700; }
.login-sub { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.login-card form { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 5px; width: 100%; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.form-group input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; width: 100%;
}
.form-group input:focus { outline: none; border-color: var(--cnc1); box-shadow: 0 0 0 3px rgba(205,171,74,.2); }
.error-banner {
  background: #fee2e2; color: var(--danger); border: 1px solid #fca5a5;
  border-radius: var(--radius); padding: 8px 12px; font-size: 13px; width: 100%;
  display: none;
}
.error-banner.visible { display: block; }

/* -----------------------------------------------------------------------
   This Week Summary
----------------------------------------------------------------------- */
.week-summary-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 24px 0 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 8px;
}
.week-summary-title {
  font-size: 13px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.workdays-badge {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 99px; padding: 3px 10px;
}

/* Week progress bar */
.week-progress-bar-wrap {
  background: var(--surface); border: 1px solid var(--border); border-top: none;
  padding: 10px 14px;
}
.week-progress-label {
  display: flex; justify-content: space-between; font-size: 11px;
  color: var(--muted); font-weight: 600; margin-bottom: 6px;
}
.week-progress-track {
  height: 6px; border-radius: 99px; background: var(--bg); overflow: hidden;
}
.week-progress-fill {
  height: 100%; border-radius: 99px; transition: width .4s ease;
}

/* Sync gap warning */
.sync-gap-warn {
  font-size: 11px; color: #d97706; margin-left: 4px; cursor: help;
}

/* Settings hint */
.settings-form-hint {
  font-size: 11px; color: var(--muted); line-height: 1.4;
}
.week-list {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius); overflow: hidden;
}
.week-day-group { }
.week-day-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: var(--bg);
  padding: 6px 14px; border-bottom: 1px solid var(--border);
}
/* -----------------------------------------------------------------------
   Settings page
----------------------------------------------------------------------- */
.settings-page-card {
  max-width: 520px; margin: 24px auto;
}
.settings-page-title {
  font-size: 16px; font-weight: 700; margin-bottom: 8px;
}
.settings-page-desc {
  font-size: 13px; color: var(--muted); margin-bottom: 20px; line-height: 1.6;
}
.settings-success {
  background: #faf5e8; color: #5c4a1e; border: 1px solid #e8d9a0;
  border-radius: var(--radius); padding: 10px 14px; font-size: 13px;
  font-weight: 600; margin-bottom: 16px;
}
.settings-form { display: flex; flex-direction: column; gap: 18px; }
.settings-form-group { display: flex; flex-direction: column; gap: 6px; }
.settings-form-label {
  font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.settings-form-input {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 15px; background: var(--bg); width: 100%; max-width: 200px;
}
.settings-form-input:focus { outline: none; border-color: var(--cnc1); box-shadow: 0 0 0 3px rgba(205,171,74,.2); }
.settings-form-actions { padding-top: 4px; }
.cnc1-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--cnc1);
  display: inline-block; flex-shrink: 0;
}
.cnc2-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--cnc2);
  display: inline-block; flex-shrink: 0;
}

/* -----------------------------------------------------------------------
   Sync banner
----------------------------------------------------------------------- */
.sync-banner {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 5px 16px;
  line-height: 1.4;
}
.sync-banner.syncing { color: var(--muted); }
.sync-banner.success { color: #5c4a1e; background: #faf5e8; }
.sync-banner.failed  { background: #fef9c3; color: #92400e; border-bottom-color: #fde68a; }

/* -----------------------------------------------------------------------
   Urgent badge
----------------------------------------------------------------------- */
.urgent-badge {
  display: inline-flex; align-items: center;
  background: #ef4444; color: #fff;
  font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 99px;
  margin-left: 6px; letter-spacing: .04em;
  text-transform: uppercase; vertical-align: middle;
}
.job-row.urgent { border-left: 3px solid #ef4444; }

/* -----------------------------------------------------------------------
   Capacity bar (enhanced)
----------------------------------------------------------------------- */
.cap-stats { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 6px; }
.cap-progress-track {
  height: 4px; border-radius: 99px; background: var(--border); overflow: hidden;
}
.cap-progress-fill {
  height: 100%; border-radius: 99px; background: var(--cnc1); transition: width .4s ease;
}
.cnc2-col .cap-progress-fill { background: var(--cnc2); }

/* -----------------------------------------------------------------------
   Week groups
----------------------------------------------------------------------- */
.week-group {
  border: 1px solid var(--border); border-top: none; background: var(--surface);
}
.week-group:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.week-group-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--bg);
  cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--border);
}
.week-group-header:hover { background: #ece7e1; }
.week-group-label {
  flex: 1; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
}
.week-group-meta { font-size: 11px; color: var(--muted); }
.week-group-chevron { font-size: 11px; color: var(--muted); }
.week-group-body .day-card { border-radius: 0; }

/* Empty day label */
.empty-label { color: var(--muted); font-style: italic; }

/* -----------------------------------------------------------------------
   Weekly report job breakdown
----------------------------------------------------------------------- */
.weekly-breakdown-wrap {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.weekly-day-breakdown { border-bottom: 1px solid var(--border); }
.weekly-day-breakdown:last-child { border-bottom: none; }
.weekly-day-breakdown-header {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted);
  background: var(--bg); padding: 6px 14px;
  border-bottom: 1px solid var(--border);
}
.text-cnc1 { color: var(--cnc1); }
.text-cnc2 { color: var(--cnc2); }

/* -----------------------------------------------------------------------
   Page section header (Schedule Settings)
----------------------------------------------------------------------- */
.page-section-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px;
}
.page-section-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; color: var(--text); }
.page-section-sub   { font-size: 13px; color: var(--muted); margin: 0; }

/* -----------------------------------------------------------------------
   Calendar grid
----------------------------------------------------------------------- */
.cal-container {
  display: flex; flex-direction: column; gap: 24px;
}
.cal-month {
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
}
.cal-month-header {
  padding: 14px 16px; font-size: 15px; font-weight: 700;
  color: var(--text); border-bottom: 1px solid var(--border);
  background: #F0EBE5;
}
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
}
.cal-dow {
  padding: 8px 0; text-align: center; font-size: 11px;
  font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; border-bottom: 1px solid var(--border);
  background: #F0EBE5;
}
.cal-day {
  min-height: 60px; padding: 6px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: flex-start;
  box-sizing: border-box;
  background: #fff;
  position: relative;
  transition: border-color .12s;
}
.cal-day:nth-child(7n) { border-right: none; }
.cal-day.empty         { background: #F7F4F2; }
.cal-day.weekend       { background: #EDE8E3; cursor: default; }
.cal-day.past          { background: #F7F4F2; cursor: default; }
.cal-day.clickable     { cursor: pointer; }
.cal-day.clickable:hover { border-color: #e8d9a0; z-index: 1; }
.cal-day.today         { outline: 2px solid #CDAB4A; outline-offset: -2px; }
.cal-day.half          { background: #fef9c3; }
.cal-day.blocked       { background: #fee2e2; }

.cal-day-num {
  font-size: 13px; font-weight: 600; color: var(--text);
  line-height: 1;
}
.cal-day.weekend .cal-day-num,
.cal-day.past    .cal-day-num { color: #b5a79e; font-weight: 400; }

.cal-indicator {
  display: inline-block; margin-top: 4px;
  font-size: 10px; font-weight: 700; padding: 1px 5px;
  border-radius: 4px; white-space: nowrap;
}
.half-ind    { background: #fef9c3; color: #ca8a04; border: 1px solid #fde68a; }
.blocked-ind { background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; }

/* -----------------------------------------------------------------------
   Edit panel
----------------------------------------------------------------------- */
.edit-panel-wrap { margin: 12px 0; }
.edit-card {
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 20px 24px;
}
.edit-date-label {
  font-size: 16px; font-weight: 700; color: var(--text);
  margin-bottom: 16px;
}
.edit-presets {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px;
}
.preset-btn {
  flex: 1; min-width: 100px; padding: 12px 8px;
  border-radius: 8px; font-size: 14px; font-weight: 600;
  border: 2px solid transparent; cursor: pointer;
  background: #F0EBE5; color: #2E2E2E;
  transition: all .15s;
}
.preset-btn.preset-full.active,
.preset-btn.preset-full:hover    { background: #faf5e8; color: #5c4a1e; border-color: #e8d9a0; }
.preset-btn.preset-half.active,
.preset-btn.preset-half:hover    { background: #fef9c3; color: #ca8a04; border-color: #fde68a; }
.preset-btn.preset-blocked.active,
.preset-btn.preset-blocked:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.edit-note-row { margin-bottom: 16px; }
.edit-note-label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text); margin-bottom: 6px;
}
.edit-note-input {
  width: 100%; box-sizing: border-box;
  padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px; font-family: inherit;
  background: #fff; color: var(--text);
  outline: none; transition: border-color .15s;
}
.edit-note-input:focus { border-color: #CDAB4A; }
.edit-actions { display: flex; align-items: center; gap: 10px; }

/* -----------------------------------------------------------------------
   Capacity summary row highlights
----------------------------------------------------------------------- */
.report-table tr.row-reduced td { background: #fef9c3; }
.report-table tr.row-blocked td { background: #fee2e2; }

/* -----------------------------------------------------------------------
   Mobile
----------------------------------------------------------------------- */
@media (max-width: 640px) {
  .columns { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
  .app-header { flex-wrap: wrap; }
  .header-title { font-size: 14px; }
  .tab-btn { padding: 10px 12px; font-size: 12px; }
  .app-main { padding: 12px; }
}
