/* SETCOM báo giá — minimal but intentional UI */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6eb;
  --border-strong: #c8ccd2;
  --text: #1a1f29;
  --muted: #6b7280;
  --primary: #1e40af;
  --primary-hover: #1e3a8a;
  --danger: #dc2626;
  --success: #059669;
  --accent: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06);
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Inter", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.center { text-align: center; }
.right { text-align: right; }
.error { color: var(--danger); margin-left: 12px; font-size: 13px; }
[x-cloak] { display: none !important; }

/* === Topbar === */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 12px 24px;
  display: flex; align-items: center; gap: 24px;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); letter-spacing: -0.01em; }
.topnav { margin-left: auto; display: flex; gap: 4px; }
.topnav a {
  padding: 6px 14px; border-radius: 6px;
  color: var(--muted); font-weight: 500;
}
.topnav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }

/* === Page === */
.page { max-width: 1400px; margin: 0 auto; padding: 24px; }
.form-shell { display: flex; flex-direction: column; gap: 20px; }

.form-header h1 {
  margin: 0 0 4px 0; font-size: 26px; letter-spacing: -0.02em;
}
.form-header p { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 16px 0; font-size: 16px; font-weight: 600; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; }
.card-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.row {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 12px;
}
label { display: flex; flex-direction: column; gap: 4px; }
label.full { display: flex; flex-direction: column; gap: 4px; }
label > span { font-size: 13px; font-weight: 500; color: var(--muted); }

.checkbox-row {
  flex-direction: row !important; align-items: center; gap: 8px !important;
  margin-top: 8px; cursor: pointer;
}
.checkbox-row input[type="checkbox"] {
  width: 16px; height: 16px; margin: 0; flex-shrink: 0;
}
.checkbox-row span { font-size: 14px; color: var(--text); font-weight: 500; }

input[type="text"], input[type="number"], input[type="date"], input[type="password"], textarea {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  background: white;
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
  width: 100%;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,64,175,.1);
}
textarea { resize: vertical; min-height: 36px; line-height: 1.4; }

/* === Buttons === */
button {
  border: 1px solid var(--border-strong);
  background: white;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all .12s;
}
button:hover { background: var(--bg); }
button.danger {
  color: var(--danger); border-color: transparent; padding: 4px 8px;
}
button.danger:hover { background: #fef2f2; }

.primary-btn, .secondary-btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none;
  padding: 8px 18px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: all .12s;
  text-decoration: none;
  white-space: nowrap;
}
.primary-btn { background: var(--primary); color: white; }
.primary-btn:hover { background: var(--primary-hover); text-decoration: none; }
.primary-btn:disabled { opacity: .5; cursor: not-allowed; }
.secondary-btn { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.secondary-btn:hover { background: var(--bg); text-decoration: none; }
.big { padding: 12px 24px; font-size: 15px; }
.secondary-btn.small { padding: 4px 10px; font-size: 12px; }

.actions-bottom {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; flex-wrap: wrap;
}

/* === Autocomplete === */
.autocomplete { position: relative; }
.suggest-list {
  position: absolute; top: 100%; left: 0; right: 0;
  background: white; border: 1px solid var(--border-strong);
  border-radius: 6px; box-shadow: var(--shadow-md);
  max-height: 280px; overflow-y: auto;
  margin: 4px 0 0 0; padding: 4px 0;
  list-style: none;
  z-index: 20;
}
.suggest-list li {
  padding: 8px 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.suggest-list li:hover { background: var(--bg); }
.suggest-list li strong { font-size: 13px; }
.suggest-list li small { color: var(--muted); font-size: 12px; }

/* === Items table — responsive, auto width, wrap === */
.items-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -12px;
  padding: 0 12px;
}
.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
  min-width: 900px;  /* ensure horizontal scroll on narrow screens */
}
.items-table th {
  text-align: left;
  font-weight: 600; color: var(--muted);
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 6px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg);
  position: sticky; top: 0; z-index: 1;
}
.items-table td {
  padding: 6px 4px; vertical-align: middle;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}
.items-table input, .items-table textarea {
  width: 100%; padding: 4px 6px; font-size: 13px;
}
.items-table textarea {
  min-height: 30px; resize: none;
  overflow: hidden;
  white-space: pre-wrap;
}
.items-table input[type="number"] { padding: 4px 4px; }
.items-table tfoot td {
  border-bottom: none; padding-top: 12px;
  font-size: 14px;
}
.items-table .grand-total { color: var(--success); font-size: 16px; }

/* Cột widths — auto layout với min-content */
.col-handle { width: 28px; }
.col-tt { width: 32px; text-align: center; }
.col-name { min-width: 200px; }
.col-unit { width: 70px; }
.col-qty { width: 70px; }
.col-price { min-width: 110px; }
.col-vat { width: 60px; }
.col-total { min-width: 140px; }
.col-notes { min-width: 140px; }
.col-del { width: 32px; }

.line-total {
  text-align: right;
  white-space: nowrap;
  color: var(--text);
}
.ordinal { text-align: center; color: var(--muted); }
.drag-handle {
  cursor: grab; color: var(--muted); user-select: none;
  font-weight: bold; text-align: center; padding: 6px 4px;
  font-size: 14px;
}
.drag-handle:active { cursor: grabbing; }
.drag-ghost { opacity: 0.4; background: #fff8e6 !important; }

.group-row {
  background: #fff8e6;
}
.group-row .group-input {
  font-weight: 700; text-transform: uppercase;
  background: transparent; border: 1px dashed transparent;
}
.group-row .group-input:focus {
  background: white; border: 1px solid var(--accent);
}

.danger-action { color: var(--danger); border-color: #fecaca; }
.danger-action:hover { background: #fef2f2; }

.paste-box {
  background: #fff8e6;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  padding: 12px; margin-bottom: 12px;
}
.paste-box textarea {
  width: 100%; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px; margin: 6px 0;
  min-height: 80px;
}
.paste-actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

.info-banner {
  background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7;
  padding: 10px 14px; border-radius: 6px;
  margin-top: 12px; font-size: 13px;
}

/* === AI usage toast === */
.ai-toast {
  position: fixed; bottom: 20px; right: 20px;
  background: #1e293b; color: white;
  padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,.2);
  font-size: 13px;
  z-index: 100;
  cursor: pointer;
  max-width: 90vw;
  animation: slideIn .3s ease;
}
.ai-toast strong { color: #fbbf24; }
@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* === Terms list === */
.terms-list {
  margin: 0; padding-left: 24px;
  display: flex; flex-direction: column; gap: 8px;
}
.terms-list li textarea { width: 100%; }

/* === Mobile === */
@media (max-width: 768px) {
  .page { padding: 12px; }
  .topbar-inner { padding: 10px 12px; gap: 12px; }
  .topnav { gap: 0; }
  .topnav a { padding: 4px 10px; font-size: 13px; }
  .form-header h1 { font-size: 20px; }
  .card { padding: 14px; }
  .row { grid-template-columns: 1fr; }
  .card-head { flex-direction: column; align-items: stretch; }
  .card-head .actions { justify-content: flex-start; }
  button, .primary-btn, .secondary-btn { font-size: 13px; padding: 6px 12px; }
  .big { padding: 10px 18px; font-size: 14px; }
  .items-table { font-size: 12px; min-width: 760px; }
  .items-table th { font-size: 10px; }
  .ai-toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}
@media (max-width: 480px) {
  .items-table { min-width: 680px; }
}

/* === Pages: success, history === */
.success-shell {
  display: flex; flex-direction: column; gap: 12px;
}
