/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f0f2f5;
  --surface:     #ffffff;
  --border:      #e2e6ea;
  --primary:     #1a56db;
  --primary-h:   #1648c6;
  --accent:      #fbbf24;
  --text:        #1e2535;
  --muted:       #6b7280;
  --danger:      #dc2626;
  --success:     #16a34a;
  --success-bg:  #f0fdf4;
  --error-bg:    #fef2f2;
  --tag-bg:      #eff6ff;
  --tag-text:    #1e40af;
  --radius:      10px;
  --shadow:      0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

html { font-size: 15px; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Top Bar ──────────────────────────────────────────────────── */
.topbar {
  background: var(--primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.topbar-inner {
  max-width: none;
  margin: 0;
  padding: 0 1rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .5px;
}
.logo-accent { color: var(--accent); }
.nav { display: flex; gap: 1rem; }
.nav-link {
  color: rgba(255,255,255,.8);
  text-decoration: none;
  font-size: .9rem;
  padding: .3rem .6rem;
  border-radius: 6px;
  transition: background .18s, color .18s;
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.15);
  color: #fff;
}

/* ── Container ────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ── Page Header ──────────────────────────────────────────────── */
.page-header { margin-bottom: 1.75rem; }
.page-header h1 { font-size: 1.7rem; font-weight: 700; }
.subtitle { color: var(--muted); margin-top: .35rem; font-size: .95rem; }
.subtitle code {
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: .1em .35em;
  border-radius: 4px;
  font-size: .9em;
}

/* ── Card ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
  margin-bottom: 1.75rem;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--text);
}

/* ── Drop Zone ────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  transition: border-color .2s, background .2s;
  cursor: default;
}
.drop-zone.drag-over {
  border-color: var(--primary);
  background: #f0f5ff;
}
.drop-zone.ts-locked {
  pointer-events: none;
  opacity: 0.45;
  cursor: not-allowed;
}
.drop-icon {
  width: 52px; height: 52px;
  margin: 0 auto .75rem;
  color: var(--muted);
}
.drop-icon svg { width: 100%; height: 100%; }
.drop-text { color: var(--muted); margin-bottom: .85rem; font-size: .95rem; }
.file-name {
  margin-top: .75rem;
  font-size: .9rem;
  font-weight: 500;
  color: var(--primary);
  min-height: 1.2em;
}

/* ── Column Hints ─────────────────────────────────────────────── */
.columns-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
  margin-top: 1.25rem;
}
.hint-label { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  padding: .18rem .65rem;
  font-size: .78rem;
  font-weight: 500;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.form-actions {
  display: flex;
  gap: .75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border-radius: 7px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .18s, transform .1s, opacity .18s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-secondary {
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid #bfdbfe;
}
.btn-secondary:hover { background: #dbeafe; }
.btn-ghost {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fca5a5;
}
.btn-ghost:hover { background: #fef2f2; }
.btn-icon { width: 18px; height: 18px; display: flex; align-items: center; }
.btn-icon svg { width: 100%; height: 100%; }

/* ── Status Message ───────────────────────────────────────────── */
.status-msg {
  margin-top: 1.25rem;
  padding: .85rem 1rem;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 500;
  border-left: 4px solid transparent;
}
.status-msg.hidden { display: none; }
.status-msg.success {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success);
}
.status-msg.error {
  background: var(--error-bg);
  color: var(--danger);
  border-color: var(--danger);
}
.status-msg.loading {
  background: #f8f9fb;
  color: var(--muted);
  border-color: var(--muted);
}

/* ── Results Card ─────────────────────────────────────────────── */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.results-header .card-title { margin-bottom: 0; }
.results-header-right {
  display: flex;
  align-items: center;
  gap: .75rem;
}
/* ── Small button modifier ──────────────────────────────────── */
.btn-sm { font-size: .78rem; padding: .28rem .7rem; }

/* ── Add-row save / cancel icon buttons ─────────────────────── */
.ts-del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #dc2626;
  font-size: .82rem;
  font-weight: 700;
  padding: .25rem .45rem;
  border-radius: 4px;
  line-height: 1;
}
.ts-del-btn:hover { background: #fee2e2; }

.ts-ar-save, .ts-ar-cancel {
  border: none; background: none; cursor: pointer;
  font-size: .82rem; font-weight: 700;
  padding: .1rem .3rem; border-radius: 4px; margin-left: .25rem;
}
.ts-ar-save   { color: #16a34a; }
.ts-ar-save:hover   { background: #d1fae5; }
.ts-ar-cancel { color: #dc2626; }
.ts-ar-cancel:hover { background: #fee2e2; }

/* ── Add-row TR highlight ─────────────────────────────────────── */
tbody tr.ts-add-row { background: #f0f9ff; }
tbody tr.ts-add-row td { padding: .4rem .5rem; }

.ts-search {
  padding: .38rem .75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: .875rem;
  width: 220px;
  outline: none;
  transition: border-color .15s;
}
.ts-search:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.badge {
  background: var(--primary);
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  padding: .25rem .7rem;
  border-radius: 20px;
}

/* ── Table ────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}
table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.td-project {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.td-project.ts-editable {
  cursor: pointer;
  position: relative;
}
.td-project.ts-editable:hover .ts-project-val {
  background: #eff6ff;
  border-radius: 3px;
  outline: 1px dashed #93c5fd;
  outline-offset: 1px;
}
.td-num-editable {
  cursor: pointer;
  position: relative;
}
.td-num-editable:hover .ts-num-val {
  background: #eff6ff;
  border-radius: 3px;
  outline: 1px dashed #93c5fd;
  outline-offset: 1px;
}
.ts-project-val {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 1px 3px;
}
.ts-project-input {
  width: 100%;
  min-width: 180px;
  box-sizing: border-box;
  padding: .25rem .45rem;
  border: 2px solid var(--primary);
  border-radius: 4px;
  font-size: .82rem;
  font-family: inherit;
  outline: none;
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
  background: #fff;
}
.ts-num-val {
  display: inline-block;
  padding: 1px 3px;
  border-radius: 3px;
}
.ts-num-input {
  width: 72px;
  box-sizing: border-box;
  padding: .25rem .4rem;
  border: 2px solid var(--primary);
  border-radius: 4px;
  font-size: .82rem;
  font-family: inherit;
  text-align: right;
  outline: none;
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
  background: #fff;
}
.ts-save-hint {
  font-size: .68rem;
  color: #64748b;
  display: block;
  margin-top: 2px;
  white-space: nowrap;
}
.td-notes {
  max-width: 260px;
  width: 200px;
  white-space: pre-wrap !important;
  word-wrap: break-word;
  overflow-wrap: break-word;
  vertical-align: top;
}
thead {
  background: #f8f9fb;
}
th {
  text-align: left;
  padding: .6rem .75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: .72rem;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th.num { text-align: right; }
td {
  padding: .6rem .75rem;
  border-bottom: 1px solid #f1f3f5;
  white-space: nowrap;
}
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

/* Approval chip */
.chip {
  display: inline-block;
  padding: .18rem .6rem;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
  text-transform: capitalize;
}
.chip-approved  { background: #d1fae5; color: #065f46; }
.chip-pending   { background: #fef9c3; color: #854d0e; }
.chip-empty     { background: #f1f3f5; color: var(--muted); }
.chip-no-po     { background: #fee2e2; color: #991b1b; }
.chip-po-ok     { background: #d1fae5; color: #065f46; }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(107,114,128,.3);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: .4rem;
}

/* Responsive */
@media (max-width: 640px) {
  .page-header h1 { font-size: 1.4rem; }
  .card { padding: 1.25rem; }
}

/* ── Period Selector ─────────────────────────────────────────── */
.period-selector-slot {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

/* dropdown wrapper */
.period-menu-wrap { position: relative; }

/* trigger button */
.period-menu-trigger {
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 14px;
  padding: .25rem .85rem;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .35rem;
  transition: background .15s;
}
.period-menu-trigger:hover { background: rgba(255,255,255,.22); }
.period-menu-active { font-weight: 700; color: var(--accent); }
.period-menu-arrow  { font-size: .7rem; opacity: .75; }

/* dropdown panel */
.period-menu-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.13);
  z-index: 200;
  overflow: hidden;
  padding: .3rem 0;
}
.period-menu-panel.open { display: block; }

.period-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: .48rem 1rem;
  font-size: .85rem;
  color: #1e293b;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
}
.period-menu-item:hover  { background: #f1f5f9; }
.period-menu-item.active { font-weight: 700; color: var(--primary); background: #eff6ff; }

.period-menu-divider { height: 1px; background: var(--border); margin: .3rem 0; }
.period-menu-new     { color: var(--primary); font-weight: 600; }
.period-menu-new:hover { background: #eff6ff; }

/* ── Period Modal ────────────────────────────────────────────── */
.period-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.period-modal-overlay.hidden { display: none; }

.period-modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 2rem;
  width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,.28);
}
.period-modal-box h3 { margin: 0 0 1.25rem; font-size: 1.1rem; }

.period-modal-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .9rem;
}
.period-modal-row label { width: 52px; font-size: .9rem; font-weight: 600; color: var(--muted); }
.period-modal-row select,
.period-modal-row input {
  flex: 1;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  outline: none;
}
.period-modal-row select:focus,
.period-modal-row input:focus { border-color: var(--primary); }

.period-modal-error { color: var(--danger,#ef4444); font-size: .82rem; min-height: 1.1rem; margin-bottom: .5rem; }

.period-modal-actions {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  margin-top: .75rem;
}
