@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  --navy: #0f1f3d;
  --blue: #2563eb;
  --blue-light: #dbeafe;
  --green: #16a34a;
  --green-light: #dcfce7;
  --yellow: #d97706;
  --yellow-light: #fef3c7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --border: #e5e7eb;
  --white: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Sarabun', sans-serif;
  background: #f8fafc;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Header ── */
.app-header {
  background: var(--navy);
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  gap: 16px;
}
.header-title { display: flex; align-items: center; gap: 12px; }
.header-icon { font-size: 28px; flex-shrink: 0; }
h1 { font-size: 17px; font-weight: 700; line-height: 1.3; }
.header-sub { font-size: 12px; opacity: 0.65; margin-top: 2px; }

.header-stats { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.stat-chip {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 6px 12px;
  text-align: center;
  min-width: 80px;
}
.stat-label { display: block; font-size: 10px; opacity: 0.65; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-val { display: block; font-size: 16px; font-weight: 700; }
.stat-val.warn { color: #fbbf24; }
.stat-val.ok { color: #4ade80; }

/* Timeline bar */
.timeline-bar {
  position: relative;
  height: 6px;
  background: rgba(255,255,255,0.08);
}
.timeline-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  transition: width 0.6s ease;
  min-width: 0;
}
.timeline-phase-mark {
  position: absolute;
  top: 0;
  height: 6px;
  width: 2px;
  background: rgba(255,255,255,0.3);
}
.timeline-label {
  position: absolute;
  top: -18px;
  font-size: 9px;
  color: rgba(255,255,255,0.45);
  transform: translateX(-50%);
  white-space: nowrap;
}

/* ── Tab Nav ── */
.tab-nav {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 82px;
  z-index: 90;
  padding: 0 24px;
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 20px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray);
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--blue); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ── Main ── */
.app-main { padding: 24px; max-width: 1100px; margin: 0 auto; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Section header ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.section-header h2 { font-size: 18px; font-weight: 600; }
.section-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── Buttons ── */
.btn-primary {
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn-primary:hover { background: #1d4ed8; }

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  padding: 7px 14px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.2); }

.btn-ghost {
  background: none;
  color: var(--gray);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.btn-ghost:hover { border-color: var(--gray); }

.btn-danger {
  background: none;
  color: var(--red);
  border: 1px solid currentColor;
  border-radius: 6px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
.btn-danger:hover { background: var(--red-light); }

/* ── Filter pills ── */
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  background: var(--gray-light);
  border: none;
  border-radius: 20px;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  color: var(--gray);
  transition: all 0.2s;
}
.pill.active { background: var(--blue); color: white; }
.pill:hover:not(.active) { background: #e5e7eb; }

/* ── Phase group ── */
.phase-group { margin-bottom: 28px; }
.phase-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.phase-pill {
  font-size: 10px;
  background: var(--gray-light);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 2px 8px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.phase-pill.phase-1 { background: var(--blue-light); color: var(--blue); }
.phase-pill.phase-2 { background: var(--green-light); color: var(--green); }
.phase-pill.phase-3 { background: var(--yellow-light); color: var(--yellow); }

/* ── Step card ── */
.step-card {
  background: white;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 7px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.step-card:hover { box-shadow: var(--shadow); }
.step-card.s-pending { border-left-color: #d1d5db; }
.step-card.s-inprogress { border-left-color: var(--blue); }
.step-card.s-done { border-left-color: var(--green); opacity: 0.75; }
.step-card.s-blocked { border-left-color: var(--red); }

.step-status-icon { font-size: 17px; flex-shrink: 0; margin-top: 2px; }

.step-body { flex: 1; min-width: 0; }

.meta-tag.assignee-tag { background: #f0fdf4; color: #15803d; }
.move-btns { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.step-card:hover .move-btns { opacity: 1; }
.move-btn { background: none; border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 10px; cursor: pointer; color: var(--gray); line-height: 1.4; }
.move-btn:hover { background: var(--gray-light); color: var(--text); }
.step-title { font-weight: 500; font-size: 14px; line-height: 1.4; }
.step-title.crossed { text-decoration: line-through; color: var(--gray); }

.step-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  flex-wrap: wrap;
}
.meta-tag {
  font-size: 11px;
  border-radius: 4px;
  padding: 2px 6px;
  background: var(--gray-light);
  color: var(--text-muted);
}
.meta-tag.cat-main { background: #f0f4ff; color: #3b5fd6; }
.meta-tag.cat-แพทย์ฯ { background: #fdf2f8; color: #9d174d; }
.meta-tag.cat-เกษตรฯ { background: #f0fdf4; color: #15803d; }
.meta-tag.cat-นิติฯ { background: #fff7ed; color: #c2410c; }
.meta-tag.cat-วิทย์ฯ { background: #f0f9ff; color: #0369a1; }
.meta-tag.cat-วิศวฯ { background: #fdf4ff; color: #9333ea; }
.meta-tag.cat-เอกสาร { background: #f8fafc; color: #475569; }
.meta-tag.due-ok { background: var(--green-light); color: var(--green); }
.meta-tag.due-soon { background: var(--yellow-light); color: var(--yellow); }
.meta-tag.due-over { background: var(--red-light); color: var(--red); }
.meta-tag.done-date { background: var(--green-light); color: var(--green); }

.step-notes-preview {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  font-style: italic;
}

/* ── Add Form ── */
.add-form {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.add-form h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full-width { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.req { color: var(--red); }
input[type="text"], input[type="number"], input[type="date"],
select, textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s;
  background: white;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  outline: none;
  box-shadow: 0 0 0 2px rgba(37,99,235,.12);
}
textarea { resize: vertical; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }

/* ── Candidate cards ── */
.candidate-group { margin-bottom: 28px; }
.group-title {
  font-size: 15px; font-weight: 600; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.candidates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 12px;
}
.candidate-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.candidate-card:hover { border-color: var(--blue); box-shadow: var(--shadow); }
.cand-field {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--blue); margin-bottom: 5px;
}
.cand-name { font-size: 14px; font-weight: 600; margin-bottom: 8px; line-height: 1.4; }
.cand-status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; border-radius: 4px; padding: 3px 8px; font-weight: 500;
}
.cs-pending { background: var(--gray-light); color: var(--gray); }
.cs-contacted { background: var(--blue-light); color: var(--blue); }
.cs-accepted { background: var(--green-light); color: var(--green); }
.cs-declined { background: var(--red-light); color: var(--red); }
.cs-approved { background: #dcfce7; color: #15803d; font-weight: 700; }
.cand-notes { font-size: 12px; color: var(--text-muted); margin-top: 8px; line-height: 1.5; }

/* ── Meeting cards ── */
.meeting-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.meeting-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; cursor: pointer;
  background: var(--gray-light);
  transition: background 0.2s;
}
.meeting-header:hover { background: #eaecf0; }
.meeting-hdr-left h4 { font-size: 15px; font-weight: 600; }
.meeting-date-tag { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.meeting-toggle { font-size: 16px; color: var(--gray); }
.meeting-body { padding: 16px; border-top: 1px solid var(--border); }
.meeting-section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--gray); margin-bottom: 6px; margin-top: 14px;
}
.meeting-section-label:first-child { margin-top: 0; }
.meeting-content { font-size: 14px; line-height: 1.7; white-space: pre-wrap; color: var(--text); }
.meeting-actions { margin-top: 14px; display: flex; gap: 8px; }

/* ── Overview ── */
.overview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card {
  background: white; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card.full-width { grid-column: 1 / -1; }
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 14px; }

.status-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.status-label { font-size: 14px; display: flex; align-items: center; gap: 7px; }
.status-num { font-size: 20px; font-weight: 700; }
.num-done { color: var(--green); }
.num-inprogress { color: var(--blue); }
.num-blocked { color: var(--red); }
.num-pending { color: var(--gray); }

.progress-track { height: 6px; background: var(--gray-light); border-radius: 3px; margin-top: 12px; }
.progress-fill { height: 6px; background: var(--green); border-radius: 3px; transition: width 0.5s; }

.legal-info { font-size: 14px; line-height: 1.8; }
.legal-info p { margin-bottom: 6px; }
.badge { display: inline; font-size: 11px; border-radius: 4px; padding: 2px 6px; font-weight: 500; }
.badge.warn { background: var(--yellow-light); color: var(--yellow); }
.badge.ok { background: var(--green-light); color: var(--green); }

.pending-list { display: flex; flex-direction: column; gap: 6px; }
.pending-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--gray-light); border-radius: 6px; font-size: 13px;
}
.pending-item.blocked { background: var(--red-light); }
.pending-item.inprogress { background: var(--blue-light); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-md);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; line-height: 1.4; }
.modal-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.5; }

.status-selector { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 4px; }
.status-opt {
  background: var(--gray-light);
  border: 2px solid transparent;
  border-radius: 7px;
  padding: 7px 13px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.status-opt:hover { border-color: #94a3b8; }
.status-opt.sel-pending { border-color: var(--gray); background: #f3f4f6; font-weight: 500; }
.status-opt.sel-inprogress { border-color: var(--blue); background: var(--blue-light); font-weight: 500; }
.status-opt.sel-done { border-color: var(--green); background: var(--green-light); font-weight: 500; }
.status-opt.sel-blocked { border-color: var(--red); background: var(--red-light); font-weight: 500; }

.modal-sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* candidate modal */
.cand-status-selector { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 4px; }
.cand-status-opt {
  background: var(--gray-light); border: 2px solid transparent;
  border-radius: 7px; padding: 6px 12px; font-family: inherit;
  font-size: 13px; cursor: pointer; transition: all 0.15s;
}
.cand-status-opt.cso-pending.sel { border-color: var(--gray); background: var(--gray-light); font-weight: 500; }
.cand-status-opt.cso-contacted.sel { border-color: var(--blue); background: var(--blue-light); font-weight: 500; }
.cand-status-opt.cso-accepted.sel { border-color: var(--green); background: var(--green-light); font-weight: 500; }
.cand-status-opt.cso-declined.sel { border-color: var(--red); background: var(--red-light); font-weight: 500; }
.cand-status-opt.cso-approved.sel { border-color: #15803d; background: #dcfce7; font-weight: 600; }

/* ── Empty state ── */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text-muted);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Responsive ── */
@media (max-width: 700px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .header-stats { flex-wrap: wrap; }
  .overview-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .app-main { padding: 16px; }
}
