/* ==========================================================================
   DD Bulk Input — Refactored CSS (drop-in compatible)
   ========================================================================== */

/* -------------------- Design Tokens -------------------- */
:root{
  /* colors */
  --bg:#fff;
  --ink:#111;
  --muted:#666;
  --border:#ddd;
  --accent:#4e89ae;
  --accent-strong:#3b6f94;
  --section:#d3d3d3;
  --thead:#e6c1e8;
  --error:#c62828;
  --success:#18a558;
  --danger:#d64545;

  /* layout */
  --container-max: 700px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 14px;

  /* spacing + type */
  --sp-1: .25rem;
  --sp-2: .5rem;
  --sp-3: .75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --font: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;

  /* preview tune */
  --preview-max: 560px;   /* lebar maks jadual preview */
  --qty-ch: 3ch;          /* lebar kolum nombor */

  /* shadow */
  --shadow-lg: 0 25px 60px rgba(0,0,0,.35);
}

/* -------------------- Base -------------------- */
* { box-sizing: border-box; }
html, body { background: var(--bg); color: var(--ink); }
body { font-family: var(--font); line-height: 1.4; }

/* -------------------- Page Shell -------------------- */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-4);
}

.title {
  font-size: 1.5rem;
  text-align: center;
  margin-bottom: var(--sp-8);
}
.title mark { background: yellow; padding: 0 var(--sp-2); }

/* -------------------- Form -------------------- */
.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-6);
}
.input-group label { font-weight: 600; }
.input-group input,
.input-group select {
  padding: .6rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  background: #fff;
}
.input-group input:focus,
.input-group select:focus { border-color: var(--accent); }

.meta-row { margin: .25rem 0 1.25rem 0; }
.muted { color: var(--muted); }
.error { color: var(--error); font-weight: 600; }

/* Invalid state */
.input-group input.invalid,
.input-group select.invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(214,69,69,.12);
}

/* Submit button */
.submit-btn {
  display: block;
  width: 100%;
  padding: .9rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background-color .15s ease, transform .02s ease;
  margin-top: var(--sp-5);
}
.submit-btn:hover { background: var(--accent-strong); }
.submit-btn:active { transform: translateY(1px); }
.submit-btn:disabled { opacity:.6; cursor:not-allowed; }

/* -------------------- Inventory Sections -------------------- */
.section { margin-bottom: var(--sp-8); }
.section-header {
  display: inline-block;
  background: var(--section);
  padding: .55rem .7rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-3);
}

/* Table */
.item-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.item-table thead th {
  background: var(--thead);
  text-align: left;
  padding: .6rem .5rem;
  font-size: .95rem;
}
.item-table th,
.item-table td {
  padding: .5rem;
  vertical-align: middle;
  text-align: left;
}
.item-table tr + tr td { border-top: 1px solid var(--border); }
.item-table th:nth-child(1),
.item-table td:nth-child(1) { width: 70%; }
.item-table th:nth-child(2),
.item-table td:nth-child(2) { width: 30%; }
.item-table input[type="number"]{
  width: 100%;
  padding: .5rem;
  font-size: .95rem;
  border: 1px solid #aaa;
  border-radius: var(--radius-md);
  box-sizing: border-box;
  background: #fff;
}
.item-table input[type="number"]:focus { border-color: var(--accent); }

/* -------------------- Modal (Preview) -------------------- */
.hidden { display: none; }
/* Important: make sure modal starts hidden even if .modal-overlay sets display */
.modal-overlay.hidden { display: none !important; }

.modal-overlay{
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: rgba(0,0,0,.45);
  z-index: 1000;
}

.modal{
  width: min(720px, 95vw);
  background: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.modal-title{ font-weight: 700; font-size: 1.05rem; }
.modal-close{
  background: transparent; border: 0; color: var(--muted);
  font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.modal-subtitle{
  padding: .8rem 1.1rem .4rem 1.1rem;
  color: var(--muted);
  font-weight: 600;
}
.modal-body{
  padding: .4rem 1.1rem 1rem 1.1rem;
  max-height: 62vh;
  overflow: auto;
}

/* ---------- Preview list: nombor rapat sebelah item ---------- */
.preview-group{
  border-top: 1px dashed var(--border);
  padding: .7rem 0 .2rem 0;
}
.preview-cat{ font-weight: 700; margin-bottom: .25rem; }

/* jadual mengecil ikut kandungan, tak penuh modal */
.preview-table{
  width: max-content;
  max-width: min(100%, var(--preview-max));
  border-collapse: collapse;
  margin: 0;                 /* align left */
}
.preview-table td{
  padding: .35rem 0;
  border-bottom: 1px dotted #eee;
  white-space: nowrap;       /* elak wrap antara nama & nombor */
}
.preview-table td.name{
  color: var(--ink);
  padding-right: .5rem;      /* jarak kecil sebelum nombor */
}
.preview-table td.qty{
  min-width: var(--qty-ch);  /* 1–3 digit; naikkan jika perlu */
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas,
               "Liberation Mono", monospace;   /* digit seragam */
  padding-left: .25rem;
}

.modal-total{ margin-top: .6rem; font-weight: 700; }

.modal-actions{
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: .9rem 1.1rem 1.1rem 1.1rem;
  border-top: 1px solid var(--border);
}

/* Buttons */
.btn{
  padding: .55rem .9rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
}
.btn:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-success{ background: var(--success); color:#fff; }
.btn-success:hover{ filter: brightness(.95); }
.btn-danger{
  background: #fff;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover{ background: rgba(214,69,69,.08); }

/* -------------------- Responsive -------------------- */
@media (max-width: 520px){
  .item-table th:nth-child(1),
  .item-table td:nth-child(1) { width: 60%; }
  .item-table th:nth-child(2),
  .item-table td:nth-child(2) { width: 40%; }
  .preview-table{ max-width: 100%; }
}
