*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface2: #f0efec;
  --border: rgba(0,0,0,0.12);
  --border-hover: rgba(0,0,0,0.25);
  --text: #1a1a18;
  --text-secondary: #6b6b67;
  --text-tertiary: #9b9b96;
  --accent: #1a1a18;
  --accent-text: #ffffff;
  --radius: 8px;
  --radius-lg: 12px;
  --info: #185FA5;
  --info-bg: #E6F1FB;
  --danger: #A32D2D;
  --danger-bg: #FCEBEB;
  --success: #3B6D11;
  --success-bg: #EAF3DE;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a18;
    --surface: #242422;
    --surface2: #2e2e2b;
    --border: rgba(255,255,255,0.1);
    --border-hover: rgba(255,255,255,0.22);
    --text: #e8e8e4;
    --text-secondary: #9b9b96;
    --text-tertiary: #6b6b67;
    --accent: #e8e8e4;
    --accent-text: #1a1a18;
    --info: #85B7EB;
    --info-bg: #0c1e33;
    --danger: #F09595;
    --danger-bg: #2d1010;
    --success: #97C459;
    --success-bg: #162208;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ── */
#app { min-height: 100vh; }

.page-center {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  min-height: 100vh;
}

.board-page { padding: 1.25rem; }

/* ── Card / Surface ── */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* ── Setup / Connect screen ── */
.setup-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
}

.setup-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.setup-card p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

/* ── Form elements ── */
.field-row { margin-bottom: 1rem; }

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
  display: block;
}

input[type=text],
input[type=password],
input[type=date],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  border: 0.5px solid var(--border-hover);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 70px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  border: 0.5px solid var(--border-hover);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:hover { background: var(--surface2); }
.btn:active { opacity: 0.8; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}
.btn-primary:hover { opacity: 0.88; background: var(--accent); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ── Status badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 20px;
  background: var(--surface2);
  border: 0.5px solid var(--border);
  color: var(--text-secondary);
}

/* ── Alerts ── */
.alert {
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.6;
  margin-bottom: 1rem;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 0.5px solid var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); border: 0.5px solid var(--success); }
.alert-info { background: var(--info-bg); color: var(--info); border: 0.5px solid var(--info); }

/* ── Header ── */
.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 10px;
}

.board-title { font-size: 18px; font-weight: 600; }
.board-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.board-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Top bar (date filter) ── */
.top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.top-bar label { font-size: 12px; color: var(--text-secondary); }
.top-bar input[type=date] { width: 136px; }

/* ── Kanban board ── */
.board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  align-items: flex-start;
  padding-bottom: 1rem;
}

/* ── Column ── */
.col {
  flex: 0 0 230px;
  background: var(--surface2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 200px;
  transition: border-color 0.15s;
}

.col.drag-target { border-color: var(--info); background: var(--info-bg); }

.col-header {
  padding: 11px 12px 9px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.col-title-wrap { display: flex; align-items: center; gap: 7px; min-width: 0; }

.col-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.col-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-sub { font-size: 10px; color: var(--text-tertiary); margin-top: 1px; }

.col-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 60px;
}

.empty-col {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
  padding: 1.5rem 0.5rem;
}

/* ── Order card ── */
.order-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  cursor: grab;
  user-select: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow);
}

.order-card:hover { border-color: var(--border-hover); }
.order-card.dragging { opacity: 0.4; cursor: grabbing; }

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.card-id { font-size: 11px; font-weight: 600; color: var(--info); }
.card-date { font-size: 10px; color: var(--text-tertiary); }
.card-customer { font-size: 12px; font-weight: 600; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { font-size: 11px; color: var(--text-secondary); }
.card-total { font-size: 12px; font-weight: 600; margin-top: 5px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 8px;
}

.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-close {
  font-size: 20px;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0 2px;
}
.modal-close:hover { color: var(--text); }

.detail-row { font-size: 12px; color: var(--text-secondary); margin-bottom: 5px; }
.detail-row strong { color: var(--text); font-weight: 500; }

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin: 1rem 0 0.5rem;
}

.product-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 12px;
}
.product-line:last-child { border-bottom: none; }
.product-name { color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-qty-price { color: var(--text-secondary); white-space: nowrap; }

/* ── Status map screen ── */
.map-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow);
}

.map-card h2 { font-size: 16px; font-weight: 600; margin-bottom: 0.25rem; }
.map-card .sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 1.25rem; }

.map-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.map-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 185px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.map-row input { flex: 1; width: auto; }

.status-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 1rem;
  line-height: 1.8;
}

/* ── Lang toggle ── */
.lang-toggle { display: flex; gap: 5px; }
.lang-toggle button {
  font-size: 12px;
  padding: 3px 9px;
  border: 0.5px solid var(--border-hover);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
}
.lang-toggle button.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid var(--border-hover);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── RTL support ── */
[dir=rtl] .board-actions { flex-direction: row-reverse; }
[dir=rtl] .card-top { flex-direction: row-reverse; }
[dir=rtl] .map-label { flex-direction: row-reverse; }
[dir=rtl] .toast { right: auto; left: 24px; }

/* ── Card product list ── */
.card-products {
  margin: 5px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-product-line {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.card-product-qty {
  color: var(--text-tertiary);
  font-size: 10px;
}

.card-product-loading {
  color: var(--text-tertiary);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 4px;
}
