:root {
  --bg: #f5f6f8;
  --panel-bg: #ffffff;
  --border: #dde1e6;
  --text: #1f2530;
  --text-muted: #6b7280;
  --primary: #b30000;
  --primary-dark: #8a0000;
  --warn-bg: #fff4f4;
  --warn-border: #d33;
  --weekend-bg: #eef0f3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Tahoma", "Sarabun", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  background: var(--primary);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.last-saved {
  font-size: 12px;
  opacity: 0.85;
}

main {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel h2 {
  margin: 0;
  font-size: 16px;
}

.panel summary {
  cursor: pointer;
}
.panel summary h2 { display: inline; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: #f0f0f0; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger {
  color: var(--primary);
  border-color: var(--primary);
  background: #fff;
}
.btn-danger:hover { background: var(--warn-bg); }

.row-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.btn-move {
  padding: 4px 8px;
  min-width: 26px;
  line-height: 1;
}
.btn-move:disabled {
  opacity: 0.35;
  cursor: default;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

td input, td select {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}
td input:hover, td select:hover { border-color: var(--border); }
td input:focus, td select:focus {
  border-color: var(--primary);
  outline: none;
  background: #fff;
}

input[type="number"] { width: 70px; }
input[type="date"] { width: 130px; }

.col-num { width: 30px; color: var(--text-muted); }
.end-date-cell { color: var(--text-muted); font-weight: 500; white-space: nowrap; }

/* Phase sub-rows (Vendor tasks: Requirement/DEV/UAT) — read as "detail rows"
   under their parent task, in both the task table and the Timeline. */
tr.phase-row td {
  background: var(--bg);
  font-size: 12px;
}
tr.phase-row td:nth-child(2) {
  color: var(--text-muted);
  padding-left: 20px;
}
.timeline-row.phase-row { height: 20px; }
.timeline-row.phase-row .timeline-label {
  padding-left: 18px;
  font-size: 11px;
  color: var(--text-muted);
}
.timeline-row.phase-row .timeline-bar { opacity: 0.85; }

.badge-warn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  text-align: center;
  line-height: 18px;
  font-size: 11px;
  cursor: help;
}

.warnings-panel {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}
.warnings-panel.hidden { display: none; }
.warnings-panel h2 { color: var(--primary); }

.warning-item {
  padding: 6px 0;
  border-bottom: 1px dashed var(--warn-border);
  font-size: 13px;
}
.warning-item:last-child { border-bottom: none; }
.warning-item .owner-name { font-weight: 700; }

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 12px;
}
.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

.timeline-scroll { overflow-x: auto; }

.timeline-grid {
  display: inline-block;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.timeline-row {
  display: grid;
  align-items: center;
  height: 26px;
  position: relative;
}

.timeline-month-row {
  display: grid;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  height: 18px;
  align-items: center;
}

.timeline-month-cell {
  text-align: center;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
}

.timeline-header-row {
  display: grid;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  height: 22px;
  align-items: center;
  border-bottom: 2px solid var(--text-muted);
}

.timeline-daycell {
  height: 100%;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
  box-sizing: border-box;
}
.timeline-daycell.weekend { background: var(--weekend-bg); }

.timeline-header-row .timeline-daycell {
  border-right: 1px solid var(--border);
  border-bottom: none;
  background: var(--bg);
}

.timeline-label {
  font-size: 12px;
  padding-right: 8px;
  white-space: nowrap;
  position: sticky;
  left: 0;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}

.timeline-bar {
  height: 16px;
  border-radius: 4px;
  font-size: 10px;
  color: #fff;
  display: flex;
  align-items: center;
  padding-left: 4px;
  overflow: hidden;
  white-space: nowrap;
  box-sizing: border-box;
}
.timeline-bar.overallocated {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.empty-note {
  color: var(--text-muted);
  font-size: 13px;
  padding: 10px 0;
}

.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 30, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-overlay.hidden { display: none; }

.login-box {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  width: min(420px, 92vw);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}
.login-box h1 {
  margin: 0 0 6px;
  font-size: 18px;
}
.login-sub {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 13px;
}
#loginForm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#loginForm input[type="password"] {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
#loginForm input[type="password"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15);
}
#loginForm button[type="submit"] {
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
#loginForm button[type="submit"]:hover {
  background: var(--primary-dark);
}
.login-error {
  margin: 10px 0 0;
  color: var(--primary);
  font-size: 13px;
}
.login-error.hidden { display: none; }

main.hidden,
.app-header.hidden {
  display: none !important;
}

@media print {
  body, .app-header, .timeline-daycell.weekend, .timeline-bar, .badge-warn, .warnings-panel {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .header-actions { display: none !important; }
  #taskTable th:last-child, #taskTable td:last-child,
  #teamTable th:last-child, #teamTable td:last-child {
    display: none !important;
  }
  input, select {
    border: none !important;
    background: transparent !important;
    padding: 2px 0 !important;
    color: var(--text) !important;
  }
  input[type="date"]::-webkit-calendar-picker-indicator { display: none !important; }
  .btn { display: none !important; }
  .panel { break-inside: avoid; box-shadow: none !important; }
  .timeline-scroll { overflow: visible !important; }
  main { padding: 8px; }
}
