:root {
  --sidebar: #111827;
  --sidebar-hover: #1f2937;
  --sidebar-active: #0d9488;
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --teal-light: #ccfbf1;
  --bg: #f1f5f9;
  --surface: #fff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
  --font: 'Inter', system-ui, sans-serif;
  --shadow: 0 1px 4px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1), 0 16px 40px rgba(0,0,0,.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; font-size: 14px; line-height: 1.5; }
.hidden { display: none !important; }
.view { min-height: 100vh; }

/* ─── Language switch ─────────────────────────────── */
.lang-switch { display: flex; gap: 4px; }
.lang-switch-login { position: fixed; top: 18px; right: 20px; z-index: 100; }
.lang-btn {
  background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.3);
  color: #fff; padding: 4px 10px; border-radius: 6px; font-size: .75rem;
  font-weight: 600; cursor: pointer; transition: .15s; letter-spacing: .04em;
}
.lang-btn:hover, .lang-btn.active { background: rgba(255,255,255,.35); }
.sidebar .lang-switch { padding: 0 0 8px; }
.sidebar .lang-btn { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.12); color: #94a3b8; font-size: .7rem; padding: 3px 8px; }
.sidebar .lang-btn:hover, .sidebar .lang-btn.active { background: rgba(255,255,255,.18); color: #fff; }

/* ─── Submenu ─────────────────────────────────────── */
.nav-item-with-submenu { position: relative; }
.submenu {
  background: rgba(0,0,0,.2); margin-left: 24px; border-radius: 6px;
  padding: 4px 0; margin-top: 4px; margin-bottom: 4px;
}
.submenu-item {
  background: transparent; border: none; color: #94a3b8; padding: 8px 16px;
  width: 100%; text-align: left; font-size: .85rem; cursor: pointer;
  transition: .15s; display: flex; align-items: center;
}

/* ─── Import/Export Column Mapping ───────────────────── */
.column-mapping-select {
  min-width: 150px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.column-mapping-select:hover {
  border-color: var(--teal);
}

.column-mapping-select.is-valid {
  border-color: var(--success);
  background: #f0fdf4;
  color: var(--success);
  font-weight: 600;
}

.import-preview-table {
  max-height: 400px;
  overflow: auto; /* Scroll both horizontal and vertical */
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.import-preview-table table {
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.import-preview-table table th, 
.import-preview-table table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 10px;
}

.import-preview-table table th:last-child, 
.import-preview-table table td:last-child {
  border-right: none;
}

.import-preview-table table thead tr:nth-child(1) th {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 10;
  box-shadow: inset 0 -1px 0 var(--border);
  height: 38px;
}

.import-preview-table table thead tr:nth-child(2) th {
  position: sticky;
  top: 38px;
  background: var(--bg-card);
  z-index: 9;
  box-shadow: inset 0 -1px 0 var(--border);
}

.submenu-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.submenu-item.active { background: var(--sidebar-active); color: #fff; }
.submenu-arrow {
  font-size: .7rem; margin-left: auto; transition: transform .2s;
  color: #94a3b8;
}

/* ─── Category Grid ───────────────────────────────── */
.category-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px; margin: 16px 0;
}
.category-check {
  display: flex; align-items: center; gap: 8px; padding: 12px;
  background: var(--bg); border: 2px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: .15s;
}
.category-check:hover { border-color: var(--teal); }
.category-check.checked { background: var(--teal-light); border-color: var(--teal); }
.category-check input { display: none; }
.category-check span { font-weight: 500; }

/* ─── Step Indicator ───────────────────────────────── */
.step-indicator {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
  font-size: .9rem; color: var(--muted);
}
.step { padding: 6px 12px; border-radius: 20px; background: var(--bg); }
.step.done { background: var(--teal-light); color: var(--teal-dark); }
.step.active { background: var(--teal); color: #fff; font-weight: 600; }
.step-sep { font-size: 1.2rem; color: var(--border); }

/* ─── Form Sections ─────────────────────────────────── */
.form-section {
  background: var(--bg); padding: 16px; border-radius: var(--radius);
  margin-bottom: 20px;
}
.form-section h3 { margin-bottom: 12px; font-size: 1rem; color: var(--text); }
.form-row-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}

/* ─── Toolbar Styling ───────────────────────────────── */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 16px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.toolbar input[type="search"],
.toolbar input[type="date"],
.toolbar select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; background: #fff; transition: .15s;
  height: 38px;
}
.toolbar input[type="search"]:focus,
.toolbar input[type="date"]:focus,
.toolbar select:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.1);
}
.toolbar .search {
  flex: 1; min-width: 200px;
}

/* ─── Orders Selection Bar ───────────────────────────── */
.orders-selection-bar {
  display: flex; align-items: center; padding: 12px 16px;
  background: var(--teal-light); border-radius: var(--radius);
  margin-bottom: 16px; border-left: 4px solid var(--teal);
}
.orders-selection-bar label {
  font-weight: 500; color: var(--teal-dark);
}
.orders-selection-bar input[type="checkbox"] {
  width: 18px; height: 18px; cursor: pointer;
  accent-color: var(--teal);
}

/* ─── Login ──────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f766e 0%, #0d9488 50%, #14b8a6 100%); padding: 24px;
}
.login-card {
  background: #fff; border-radius: 20px; padding: 44px 40px;
  width: 100%; max-width: 400px; text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,.18);
}
.login-logo {
  width: 60px; height: 60px; background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  color: #fff; border-radius: 16px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 800; margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(13,148,136,.3);
}
.login-card h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 4px; }
.login-card > p { color: var(--muted); font-size: .875rem; margin-bottom: 28px; }
.login-card input {
  width: 100%; padding: 13px 15px; border: 1.5px solid var(--border);
  border-radius: var(--radius); margin-bottom: 12px; font-size: .9rem; font-family: var(--font);
  transition: .15s; background: #f8fafc;
}
.login-card input:focus { outline: none; border-color: var(--teal); background: #fff; box-shadow: 0 0 0 4px rgba(13,148,136,.12); }
.hint { margin-top: 20px; font-size: .76rem; color: var(--muted); }
.hint code { background: #f1f5f9; padding: 2px 7px; border-radius: 4px; font-family: monospace; }
.alert-error { background: var(--danger-light); color: var(--danger); padding: 10px 14px; border-radius: var(--radius); font-size: .85rem; margin-bottom: 12px; border: 1px solid #fecaca; }

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

.sidebar {
  width: 230px; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; flex-shrink: 0;
  box-shadow: 2px 0 12px rgba(0,0,0,.15);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
  padding: 20px 18px; font-weight: 800; font-size: 1.1rem; color: #fff;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.07); letter-spacing: .01em;
}
.logo-sm {
  width: 34px; height: 34px; background: var(--teal); border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .9rem; font-weight: 800; flex-shrink: 0;
}
.sidebar nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; cursor: pointer; font-size: .84rem; color: #94a3b8;
  border: none; background: none; width: 100%; text-align: left; transition: .15s;
  white-space: nowrap; overflow: hidden;
}
.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-item.expanded { color: #fff; font-weight: 600; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #475569; padding: 14px 12px 5px; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.07); }
#sidebar-user { font-size: .78rem; color: #94a3b8; margin-bottom: 8px; line-height: 1.4; }
#sidebar-user strong { color: #cbd5e1; display: block; }

.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.workspace-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 15px 26px; display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 1px 0 var(--border);
}
.workspace-header h1 { font-size: 1.2rem; font-weight: 700; }
.page-content { flex: 1; padding: 24px; overflow-y: auto; }

/* ─── Buttons ────────────────────────────────────── */
button, .btn-teal, .btn-outline, .btn-danger, .btn-ghost-sm {
  font-family: var(--font); cursor: pointer; border-radius: var(--radius);
  font-size: .84rem; font-weight: 500; padding: 9px 16px; border: none; transition: .15s;
}
.btn-teal { background: var(--teal); color: #fff; }
.btn-teal:hover { background: var(--teal-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(13,148,136,.3); }
.btn-teal:active { transform: none; }
.btn-outline { background: var(--surface); border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; transform: translateY(-1px); }
.btn-ghost-sm { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); color: #94a3b8; padding: 7px 12px; font-size: .78rem; width: 100%; }
.btn-ghost-sm:hover { background: rgba(255,255,255,.16); color: #e2e8f0; }
.btn-block { width: 100%; padding: 13px; font-size: .95rem; font-weight: 600; }
.btn-sm { padding: 6px 12px; font-size: .78rem; }
.btn-add-inline {
  width: 34px; height: 36px; padding: 0; border-radius: 8px;
  background: var(--teal-light); color: var(--teal-dark); font-size: 1.2rem;
  border: 1.5px solid var(--teal); flex-shrink: 0;
}
.btn-add-inline:hover { background: var(--teal); color: #fff; }

/* ─── Cards & Toolbar ────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 18px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-head h3 { font-size: .95rem; font-weight: 600; }
.card-body { padding: 20px; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.search {
  padding: 9px 14px; border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: .84rem; flex: 1; max-width: 320px; font-family: var(--font); background: var(--surface);
}
.search:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,.1); }

/* ─── Tables ─────────────────────────────────────── */
.table-responsive-wrapper {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-top: 10px;
}
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .82rem; min-width: 1200px; text-align: left; }
.data-table th {
  padding: 11px 14px; text-align: left; font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  background: #f8fafc; border-bottom: 1.5px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; white-space: nowrap; }
.data-table tbody tr:hover td { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.td-actions { display: flex; gap: 6px; }

/* Sticky right column */
.data-table th.sticky-action,
.data-table td.sticky-action {
  position: sticky;
  right: 0;
  z-index: 10;
  box-shadow: -3px 0 5px rgba(0,0,0,0.03);
}
.data-table th.sticky-action {
  background-color: #f8fafc; /* same as table header */
}
.data-table td.sticky-action {
  background-color: #ffffff; /* same as row, or matches hover below */
}
.data-table tbody tr:hover td.sticky-action {
  background-color: #f8fafc; /* match hover row bg */
}

/* ─── Stat cards (KPI) ───────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 22px; }
.kpi-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px 20px; border: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
.kpi-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpi-val { font-size: 1.4rem; font-weight: 800; color: var(--text); line-height: 1.2; }
.kpi-sub { font-size: .74rem; color: var(--muted); }
.kpi-card.accent { background: linear-gradient(135deg, var(--teal-dark), var(--teal)); color: #fff; }
.kpi-card.accent .kpi-label { color: rgba(255,255,255,.75); }
.kpi-card.accent .kpi-val { color: #fff; }
.kpi-card.accent .kpi-sub { color: rgba(255,255,255,.7); }

/* ─── Widgets row (invoice) ──────────────────────── */
.widgets-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.widget {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow);
}
.widget.active { border-color: var(--teal); }
.widget-icon { font-size: 1.4rem; }
.widget-val { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.widget-label { font-size: .72rem; color: var(--muted); margin-top: 2px; }

/* ─── Invoice table ──────────────────────────────── */
.invoice-table-wrap { overflow-x: auto; }
.invoice-table { width: 100%; border-collapse: collapse; font-size: .8rem; min-width: 700px; }
.invoice-table th {
  padding: 10px 12px; white-space: nowrap; text-align: center;
  background: #f8fafc; border-bottom: 1.5px solid var(--border);
  font-size: .7rem; text-transform: uppercase; color: var(--muted); letter-spacing: .05em;
}
.invoice-table td { padding: 9px 12px; border-bottom: 1px solid #f1f5f9; text-align: center; vertical-align: middle; }
.invoice-table tbody tr:hover { background: #fafcff; }
.invoice-table td.name-col { text-align: left; min-width: 180px; font-weight: 500; }
.invoice-table input[type="number"] {
  width: 74px; padding: 6px 8px; border: 1.5px solid var(--border); border-radius: 6px;
  text-align: center; font-size: .8rem; font-family: var(--font); background: #f8fafc;
  transition: .15s;
}
.invoice-table input[type="number"]:focus { outline: none; border-color: var(--teal); background: #fff; }
.invoice-table .calc-cell { background: #f0fdf4; font-weight: 600; color: var(--teal-dark); }
.invoice-table img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.img-placeholder { width: 40px; height: 40px; background: #e2e8f0; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: .6rem; color: var(--muted); }
.tfoot-row td { background: #f8fafc; font-weight: 700; font-size: .85rem; }

/* ─── Category selector ──────────────────────────── */
.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 16px 0; }
.category-check {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: .15s;
  background: var(--surface);
}
.category-check:hover { border-color: var(--teal); }
.category-check input { width: 17px; height: 17px; accent-color: var(--teal); flex-shrink: 0; }
.category-check.checked { border-color: var(--teal); background: var(--teal-light); }

.step-indicator { display: flex; gap: 8px; margin-bottom: 20px; align-items: center; }
.step-indicator::before { content: ''; }
.step { padding: 6px 16px; border-radius: 20px; font-size: .78rem; font-weight: 500; background: #e2e8f0; color: var(--muted); }
.step.active { background: var(--teal); color: #fff; }
.step.done { background: var(--teal-light); color: var(--teal-dark); }
.step-sep { color: #cbd5e1; font-size: .85rem; }

/* ─── Orders ─────────────────────────────────────── */
.orders-filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-btn { padding: 6px 14px; border-radius: 20px; font-size: .78rem; font-weight: 500; border: 1.5px solid var(--border); background: var(--surface); cursor: pointer; color: var(--muted); transition: .15s; }
.filter-btn:hover { border-color: var(--teal); color: var(--teal); }
.filter-btn.active { background: var(--teal); color: #fff; border-color: var(--teal); }

.order-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 12px; box-shadow: var(--shadow); transition: .15s;
}
.order-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.09); }
.order-card-head { display: flex; justify-content: space-between; align-items: flex-start; }
.order-meta { font-size: .76rem; color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 12px; }
.order-meta span { display: flex; align-items: center; gap: 4px; }
.order-items-preview { font-size: .78rem; color: var(--muted); margin: 10px 0; padding: 8px 12px; background: #f8fafc; border-radius: 6px; }
.order-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid #f1f5f9; }
.status-badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: .7rem; font-weight: 700; margin-left: 8px; }
.status-new { background: #dbeafe; color: #1d4ed8; }
.status-assembling { background: #fef3c7; color: #b45309; }
.status-shipped { background: #d1fae5; color: #047857; }
.status-returned { background: #fce7f3; color: #be185d; }
.status-cancelled { background: #f1f5f9; color: #64748b; }
.status-select { padding: 6px 10px; border: 1.5px solid var(--border); border-radius: 7px; font-size: .78rem; font-family: var(--font); background: var(--surface); cursor: pointer; }
.status-select:focus { outline: none; border-color: var(--teal); }

.badge-debt { background: #fef2f2; color: #b91c1c; padding: 2px 8px; border-radius: 12px; font-size: .72rem; font-weight: 600; }
.badge-prepay { background: #ecfdf5; color: #047857; padding: 2px 8px; border-radius: 12px; font-size: .72rem; font-weight: 600; }
.badge-zero { background: #f1f5f9; color: #64748b; padding: 2px 8px; border-radius: 12px; font-size: .72rem; }

/* ─── Modals ─────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 20px; backdrop-filter: blur(2px);
}
.modal-dialog {
  background: #fff; border-radius: 16px; width: 100%; max-height: 92vh;
  overflow-y: auto; overflow-x: hidden; position: relative; box-shadow: 0 32px 64px rgba(0,0,0,.22);
  animation: modalIn .22s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.96) translateY(10px); } to { opacity: 1; transform: none; } }
.modal-lg { width: 900px; max-width: 95vw; }
.modal-xl { max-width: 980px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 26px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 1.05rem; font-weight: 700; }
.modal-close { position: absolute; top: 15px; right: 15px; background: #f1f5f9; border: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; line-height: 1; z-index: 10; }
.modal-close:hover { background: #e2e8f0; color: var(--text); }
.modal-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); padding: 0 26px; }
.modal-tab { background: none; border: none; padding: 12px 16px; cursor: pointer; font-size: .84rem; color: var(--muted); border-bottom: 2.5px solid transparent; margin-bottom: -1px; font-weight: 500; transition: .15s; }
.modal-tab.active { color: var(--teal); border-bottom-color: var(--teal); font-weight: 700; }
.modal-tab-panel { padding: 22px 26px; }
.modal-footer { padding: 16px 26px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; align-items: center; }

/* ─── Forms ──────────────────────────────────────── */
.form-section { margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.form-section:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.form-section h3 { font-size: .85rem; font-weight: 700; color: var(--text); margin-bottom: 16px; text-transform: uppercase; letter-spacing: .06em; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: .75rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 10px 13px; border: 1.5px solid var(--border);
  border-radius: var(--radius); font-size: .875rem; font-family: var(--font);
  background: #f8fafc; transition: .15s; color: var(--text);
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none; border-color: var(--teal); background: #fff;
  box-shadow: 0 0 0 3px rgba(13,148,136,.1);
}
.form-row input[readonly] { background: #e2e8f0; color: var(--muted); cursor: not-allowed; }
.form-row-2, .form-row-3 { display: grid; gap: 14px; margin-bottom: 14px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-2 .form-row, .form-row-3 .form-row { margin-bottom: 0; }
.field-hint { display: block; font-size: .72rem; color: var(--muted); margin-top: 4px; }
.select-with-add { display: flex; gap: 6px; }
.select-with-add select { flex: 1; }

.photo-preview {
  height: 130px; background: #f8fafc; border: 2px dashed var(--border);
  border-radius: var(--radius); display: flex; align-items: center; justify-content: center;
  color: var(--muted); margin-top: 10px; overflow: hidden; font-size: .85rem;
}
.photo-preview img { max-height: 100%; max-width: 100%; object-fit: contain; }

/* ─── Return modal ───────────────────────────────── */
.return-type-btns { display: flex; gap: 10px; padding: 18px 26px 0; }
.order-total-label { margin-right: auto; font-weight: 700; color: var(--teal-dark); font-size: .95rem; }

/* ─── Checkbox list ──────────────────────────────── */
.checkbox-list { padding: 18px 26px; display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; }
.checkbox-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: .15s; }
.checkbox-item:hover { border-color: var(--teal); background: #f0fdf4; }
.checkbox-item input { width: 17px; height: 17px; accent-color: var(--teal); }
.checkbox-item.checked { border-color: var(--teal); background: var(--teal-light); }

/* ─── Dashboard ──────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.dash-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.dash-card h4 { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 16px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 90px; gap: 10px; align-items: center; margin-bottom: 10px; font-size: .8rem; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 7px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--teal-dark), #14b8a6); border-radius: 4px; min-width: 4px; transition: width .6s ease; }
.bar-val { text-align: right; font-weight: 600; color: var(--teal-dark); white-space: nowrap; }
.progress-track { height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; margin: 6px 0 4px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--teal-dark), #14b8a6); transition: width .6s ease; }

/* Weekly sales chart */
.chart-wrap { overflow-x: auto; padding-top: 8px; }
.chart-bars { display: flex; align-items: flex-end; gap: 8px; height: 100px; padding: 0 4px; }
.chart-bar-col { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; min-width: 40px; }
.chart-bar { background: linear-gradient(180deg, #14b8a6, var(--teal-dark)); border-radius: 5px 5px 0 0; width: 100%; transition: height .6s ease; min-height: 3px; }
.chart-bar:hover { opacity: .8; }
.chart-label { font-size: .65rem; color: var(--muted); white-space: nowrap; }
.chart-val { font-size: .65rem; font-weight: 600; color: var(--teal-dark); }

/* ─── Plans page progress ────────────────────────── */
.plan-row { padding: 14px 0; border-bottom: 1px solid var(--border); }
.plan-row:last-child { border-bottom: none; }
.plan-row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.plan-agent-name { font-weight: 600; font-size: .9rem; }
.plan-pct { font-size: .8rem; font-weight: 700; color: var(--teal-dark); }
.plan-details { font-size: .75rem; color: var(--muted); display: flex; gap: 16px; margin-top: 4px; }

/* ─── Clients / territory cards ──────────────────── */
.territory-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 12px; display: flex; justify-content: space-between;
  align-items: center; box-shadow: var(--shadow);
}
.territory-name { font-weight: 600; font-size: .95rem; }
.territory-meta { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.territory-actions { display: flex; gap: 8px; }

/* ─── Toast & notifications ──────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1e293b; color: #fff; padding: 12px 18px; border-radius: var(--radius);
  font-size: .84rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 360px;
  animation: slideIn .3s cubic-bezier(.175, .885, .32, 1.275);
  display: flex; align-items: center; gap: 8px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: #0ea5e9; }
.cash-notification {
  position: fixed; top: 24px; right: 24px; z-index: 2000;
  background: var(--success); color: #fff; padding: 14px 20px;
  border-radius: var(--radius); box-shadow: var(--shadow-md); font-weight: 600; animation: slideIn .3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; font-size: .9rem; }
.empty::before { content: '📭'; display: block; font-size: 2rem; margin-bottom: 10px; }

/* ─── Agent order mode label ─────────────────────── */
.invoice-mode { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.category-tag { background: var(--teal-light); color: var(--teal-dark); padding: 4px 10px; border-radius: 20px; font-size: .76rem; font-weight: 600; }

/* ─── Cash Modal Styles ─────────────────────────── */
.cash-totals {
  background: var(--bg-light);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 16px 0;
}
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.total-row:last-child {
  border-bottom: none;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--teal-dark);
}
.payment-breakdown {
  display: flex;
  gap: 16px;
  font-size: .85rem;
  color: var(--muted);
}
#cash-table input[type="number"],
#cash-table input[type="text"] {
  width: 100px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: .85rem;
}
#cash-table input[type="text"] {
  width: 150px;
}

/* ─── Responsive ─────────────────────────────────── */
@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) {
  .sidebar { width: 62px; }
  .sidebar-brand span:not(.logo-sm), .nav-item span, #sidebar-user, .sidebar .lang-switch { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .widgets-row { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 50;
    width: 250px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .sidebar-brand span:not(.logo-sm), .nav-item span, #sidebar-user, .sidebar .lang-switch { display: inline-block; }
  #btn-mobile-menu { display: block !important; }
  .kpi-row { grid-template-columns: 1fr; }
  .global-search-container { margin-left: 10px !important; flex: 1; }
  #global-search-input { width: 100% !important; }
}

/* ─── Global Search Dropdown & Pagination ───────────────── */
.global-search-item {
  padding: 10px 15px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.global-search-item:hover { background: #f8fafc; }
.global-search-item:last-child { border-bottom: none; }

.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 15px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.pagination-controls select, .pagination-controls button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
  cursor: pointer;
}
.pagination-controls button:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination-controls span { font-size: 0.85rem; color: var(--muted); }
/* ── Client Profile Layout ── */
.profile-grid {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 992px) {
  .profile-grid { grid-template-columns: 1fr; }
}

.profile-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid #e2e8f0;
}

.profile-photo {
  margin-bottom: 15px;
}

.profile-balance-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 20px;
}
.balance-positive { background-color: #d1fae5; color: #065f46; }
.balance-negative { background-color: #fee2e2; color: #b91c1c; }

.client-info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #e2e8f0;
  font-size: 13px;
}
.client-info-row:last-child {
  border-bottom: none;
}
.client-info-label {
  color: #64748b;
  width: 40%;
}
.client-info-value {
  color: #0f172a;
  font-weight: 500;
  width: 60%;
  text-align: right;
  word-wrap: break-word;
  white-space: normal;
}

.profile-agents-list {
  background: var(--bg);
  padding: 12px;
  border-radius: var(--radius);
  margin-top: 20px;
}

/* ── Tabs ── */
.tabs-header {
  display: flex;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  background: none;
  border: none;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  font-size: 1rem;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-pane {
  display: none;
  animation: fadeIn 0.3s ease;
}
.tab-pane.active { display: block; }

/* ── 2-Column Modal ── */
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 768px) {
  .modal-grid { grid-template-columns: 1fr; }
}
.modal-lg .modal-content {
  max-width: 900px;
}

/* ── Agent Assignment Widget ── */
.agent-assignment-item {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--bg);
  padding: 10px;
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.agent-assignment-days {
  display: flex;
  gap: 4px;
}
.day-checkbox {
  display: none;
}
.day-label {
  padding: 4px 8px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}
.day-checkbox:checked + .day-label {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

#modal-payment input, #modal-payment select, #modal-payment textarea {
  border-radius: 6px;
  border: 1px solid #ced4da;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
#modal-payment input:focus, #modal-payment select:focus, #modal-payment textarea:focus {
  border-color: #80bdff;
  box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}
#modal-payment .modal-content { gap: 15px !important; }

