:root {
  --primary: #2a5a9c;
  --primary-dark: #1c3f70;
  --danger: #c0392b;
  --bg: #ece9d8;
  --card-bg: #ffffff;
  --text: #1a1a1a;
  --border: #a9c2de;
  --grid-border: #b9c9de;
  --grid-header: #dce8f8;
  --grid-header-dark: #c3d8f2;
  --edit-row: #ffffcc;
  --gray-badge: #8a8f98;
  --yellow-badge: #c78a00;
  --green-badge: #1e7e3e;
  font-size: 13px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Malgun Gothic", "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  flex-direction: column;
  background: linear-gradient(to bottom, #3a6ea5, #234a78);
  color: white;
  border-bottom: 2px solid #16324f;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.brand {
  font-size: 1.05rem;
  font-weight: 700;
}

.tab-groups {
  display: flex;
  gap: 4px;
}

.group-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 5px 16px;
  border-radius: 3px;
  font-size: 0.88rem;
  cursor: pointer;
  font-weight: 700;
}

.group-btn.active {
  background: #ffcf40;
  color: #16324f;
  border-color: #ffcf40;
}

.tabs {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  padding: 4px 12px 6px;
  background: rgba(0,0,0,0.15);
}

.tab-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: white;
  padding: 5px 12px;
  border-radius: 3px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
}

.tab-btn.active {
  background: white;
  color: var(--primary);
}

.lang-switch {
  display: flex;
  gap: 4px;
}

.lang-btn {
  background: transparent;
  border: 1px solid white;
  color: white;
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8rem;
}

.lang-btn.active {
  background: white;
  color: var(--primary);
}

main {
  padding: 12px;
  max-width: 1600px;
  margin: 0 auto;
}

@media print {
  .topbar, .no-print { display: none !important; }
  main { max-width: 100%; padding: 0; }
  body { background: white; }
  .card { box-shadow: none; }
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--grid-border);
  border-radius: 3px;
  padding: 10px 12px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.card h2 {
  margin: 0 0 8px;
  padding-bottom: 4px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
  border-bottom: 2px solid var(--primary);
}

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}

.grid-form label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-weight: 600;
  font-size: 0.82rem;
}

.grid-form .full { grid-column: 1 / -1; }

input[type="text"], input[type="number"], input[type="date"], input[type="month"], input[type="datetime-local"], select {
  padding: 4px 6px;
  border: 1px solid #8ba5c4;
  border-radius: 2px;
  font-size: 0.85rem;
  font-family: inherit;
  background: white;
}

input:focus, select:focus {
  outline: 1px solid var(--primary);
  border-color: var(--primary);
}

.btn {
  padding: 5px 12px;
  border-radius: 3px;
  border: 1px solid #9fb4cc;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(to bottom, #ffffff, #e4ecf6);
  color: var(--text);
}
.btn:hover { background: linear-gradient(to bottom, #f2f7fd, #d5e2f2); }
.btn:active { background: #cfe0f2; }

.btn-primary {
  background: linear-gradient(to bottom, #4c86c6, #2a5a9c);
  color: white;
  border-color: var(--primary-dark);
}
.btn-primary:hover { background: linear-gradient(to bottom, #5a92d0, #234a78); }

.btn-danger {
  background: linear-gradient(to bottom, #e0685c, var(--danger));
  color: white;
  border-color: #8f2418;
}
.btn-danger:hover { background: linear-gradient(to bottom, #e8776c, #a53326); }

.btn-small {
  padding: 3px 9px;
  font-size: 0.78rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.toolbar-row {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-bottom: 6px;
}

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

.batch-date-pick-wrap {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--grid-border);
}

.batch-date-item-row { cursor: pointer; }
.batch-date-item-row:hover { background: var(--grid-header); }
.batch-date-item-row.selected { background: var(--edit-row); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th, td {
  text-align: left;
  padding: 4px 8px;
  border: 1px solid var(--grid-border);
  white-space: nowrap;
}

th {
  color: var(--primary-dark);
  font-size: 0.8rem;
  background: linear-gradient(to bottom, var(--grid-header), var(--grid-header-dark));
  font-weight: 700;
}

th.sortable-col {
  cursor: pointer;
  user-select: none;
}

th.sortable-col:hover { background: var(--grid-header-dark); }

th.sortable-col.sorted { color: var(--primary); }

th.sortable-col.sorted::after { content: attr(data-arrow); }

tbody tr:nth-child(even) { background: #f4f8fd; }
tbody tr:hover { background: #eaf2fc; }

tr.grid-row-dirty, tr.grid-row-new { background: var(--edit-row) !important; }

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  margin-left: 8px;
}

.badge-unplanned { background: var(--gray-badge); }
.badge-partial { background: var(--yellow-badge); }
.badge-planned { background: var(--green-badge); }
.badge-shortage { background: var(--danger); }
.badge-fulfilled { background: var(--green-badge); }

.plans-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 10px;
  align-items: start;
}

@media (max-width: 900px) {
  .plans-layout { grid-template-columns: 1fr; }
  .grid-form { grid-template-columns: 1fr; }
}

.order-rows-header {
  display: grid;
  grid-template-columns: 1fr 1fr 28px;
  gap: 8px;
  font-weight: 600;
  font-size: 0.8rem;
  color: #555;
  margin-bottom: 4px;
}

.order-row {
  display: grid;
  grid-template-columns: 1fr 1fr 28px;
  gap: 8px;
  margin-bottom: 5px;
}

.order-row .btn-remove-row {
  padding: 0;
  width: 28px;
  height: 28px;
  font-size: 0.95rem;
  line-height: 1;
}

.row-selected { background: #dfeaf9 !important; }

.order-no-review {
  color: #ffe600;
  background: #c0392b;
  padding: 1px 7px;
  border-radius: 2px;
  font-weight: 700;
}

.price-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.price-header .filter-row { align-items: center; }

.full-grow { flex: 1; }

.full-grow input[type="text"] {
  width: 100%;
}

.filter-item-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.82rem;
}

.filter-item-label select {
  padding: 4px 6px;
  border: 1px solid #8ba5c4;
  border-radius: 2px;
  font-size: 0.82rem;
  min-width: 180px;
}

.filter-row {
  display: flex;
  gap: 5px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 4px 10px;
  border-radius: 2px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8rem;
}

.filter-btn.active {
  border-color: var(--primary-dark);
  background: var(--primary);
  color: white;
}

.order-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 600px;
  overflow-y: auto;
}

.order-item {
  border: 1px solid var(--grid-border);
  border-radius: 2px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 0.82rem;
}

.order-item:hover { border-color: var(--primary); background: #f4f8fd; }
.order-item.selected { border-color: var(--primary); background: #dfeaf9; }

.order-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.order-item-bottom { color: #555; font-size: 0.78rem; }

.order-date-header {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--primary-dark);
  background: var(--grid-header);
  padding: 4px 8px;
  border-radius: 2px;
  margin-top: 8px;
}

.order-date-header:first-child { margin-top: 0; }

.empty-hint {
  color: #888;
  font-size: 0.9rem;
  padding: 24px 0;
  text-align: center;
}

.hidden { display: none !important; }

.order-info-box {
  background: #f0f5fb;
  border: 1px solid var(--grid-border);
  border-radius: 2px;
  padding: 6px 10px;
  margin-bottom: 8px;
  line-height: 1.5;
  font-size: 0.85rem;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: white;
  padding: 8px 16px;
  border-radius: 3px;
  font-size: 0.85rem;
  z-index: 1000;
}

.toast-error { background: var(--danger); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal {
  background: white;
  border: 1px solid var(--grid-border);
  border-radius: 3px;
  padding: 16px;
  max-width: 400px;
  width: 90%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 14px;
}

.price-history-modal {
  max-width: 480px;
}

.price-change-up { color: var(--danger); font-weight: 700; }
.price-change-down { color: var(--primary); font-weight: 700; }
.price-change-flat { color: var(--gray-badge); }

.material-req-modal {
  max-width: 820px;
}

.material-shortage { color: var(--danger); font-weight: 700; }
.material-sufficient { color: var(--green-badge); }

.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(to bottom, #3a6ea5, #16324f);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

.login-box {
  background: white;
  border-radius: 4px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.login-brand {
  text-align: center;
  font-size: 1.3rem;
  color: var(--primary-dark);
  margin-bottom: 8px;
}

.login-box label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 8px;
  color: white;
  font-size: 0.85rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  vertical-align: middle;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch span {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #ccc;
  border-radius: 999px;
  transition: 0.2s;
}

.switch span:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + span { background-color: var(--primary); }
.switch input:checked + span:before { transform: translateX(20px); }

.hint-text {
  color: #666;
  font-size: 0.78rem;
  margin: -4px 0 8px;
}

.import-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-input {
  width: 80px;
  padding: 3px 5px;
  border: 1px solid #8ba5c4;
  border-radius: 2px;
  font-size: 0.82rem;
}

.dim-text {
  color: #888;
  font-size: 0.75rem;
}

/* ---------- Gantt ---------- */

.gantt-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.gantt-range-label {
  font-weight: 600;
  color: #555;
}

.gantt-legend {
  margin-left: auto;
  display: flex;
  gap: 12px;
}

.gantt-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: #555;
}

.gantt-legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.gantt-chart {
  overflow-x: auto;
  padding-bottom: 10px;
}

.gantt-grid {
  width: max-content;
}

.gantt-header-row, .gantt-row {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.gantt-row-label {
  width: 150px;
  flex-shrink: 0;
  padding: 10px 12px;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  position: sticky;
  left: 0;
  background: var(--card-bg);
  z-index: 1;
}

.gantt-days {
  display: flex;
  flex-shrink: 0;
}

.gantt-day-col {
  flex-shrink: 0;
  text-align: center;
  font-size: 0.8rem;
  color: #666;
  padding: 6px 2px 0;
  border-left: 1px solid var(--border);
}

.gantt-hour-ticks {
  display: flex;
  border-top: 1px solid #eee;
  margin-top: 4px;
}

.gantt-hour-tick {
  flex: 1;
  text-align: center;
  font-size: 0.65rem;
  color: #999;
  border-left: 1px solid #f0f2f5;
  padding-top: 2px;
}

.gantt-track {
  position: relative;
  flex-shrink: 0;
  display: flex;
  min-height: 52px;
  background-image:
    repeating-linear-gradient(
      to right,
      transparent,
      transparent calc(var(--gantt-hour-w) * 24 - 1px),
      var(--grid-border) calc(var(--gantt-hour-w) * 24 - 1px),
      var(--grid-border) calc(var(--gantt-hour-w) * 24)
    ),
    repeating-linear-gradient(
      to right,
      transparent,
      transparent calc(var(--gantt-hour-w) * 6 - 1px),
      #f0f2f5 calc(var(--gantt-hour-w) * 6 - 1px),
      #f0f2f5 calc(var(--gantt-hour-w) * 6)
    );
}

.gantt-grid-col {
  flex: 1;
  border-left: 1px solid #f0f2f5;
}

.gantt-bar {
  position: absolute;
  top: 8px;
  height: 36px;
  border-radius: 8px;
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 8px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
