:root {
  --navy-950: #071427;
  --navy-900: #0b1f3a;
  --navy-800: #122a4a;
  --navy-700: #1b3a63;
  --blue-600: #2563eb;
  --blue-500: #3b6ef0;
  --violet-500: #6d5ae6;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-muted: #f8f9fc;
  --border: #e4e9f0;
  --border-strong: #cfd8e6;
  --text: #152033;
  --text-muted: #5c6b80;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --success: #0f766e;
  --success-bg: #f0fdfa;
  --warning: #b54708;
  --shadow: 0 10px 30px rgba(11, 31, 58, 0.06);
  --shadow-sm: 0 1px 2px rgba(11, 31, 58, 0.06), 0 8px 24px rgba(11, 31, 58, 0.04);
  --radius: 16px;
  --radius-sm: 12px;
  --font: Inter, "IBM Plex Sans Arabic", Tajawal, system-ui, sans-serif;
  --arabic: Tajawal, "IBM Plex Sans Arabic", Inter, sans-serif;
  --sidebar: 272px;
  --topbar: 72px;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { font-size: 16px; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

body { overflow-x: clip; }

img { max-width: 100%; display: block; }

a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-weight: 650; letter-spacing: -0.02em; margin: 0 0 0.4em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.15rem; }

p { margin: 0 0 1rem; color: var(--text-muted); }

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--navy-900);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 100;
}
.skip-link:focus { left: 8px; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
}

.auth-brand {
  display: none;
  background:
    radial-gradient(1200px 500px at -10% -20%, rgba(109, 90, 230, 0.18), transparent 50%),
    radial-gradient(800px 400px at 110% 110%, rgba(37, 99, 235, 0.22), transparent 45%),
    linear-gradient(165deg, var(--navy-950), var(--navy-800));
  color: #fff;
  padding: 48px;
  position: relative;
  overflow: hidden;
}

.auth-brand::after {
  content: "";
  position: absolute;
  inset: auto -80px -80px auto;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.08);
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--blue-500), var(--violet-500));
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.auth-brand h2 { color: #fff; font-size: 2rem; max-width: 16ch; margin-top: 48px; }
.auth-brand p { color: rgba(255,255,255,0.72); max-width: 36ch; }
.auth-points { list-style: none; padding: 0; margin: 32px 0 0; }
.auth-points li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  color: rgba(255,255,255,0.82);
  margin-bottom: 14px;
  font-size: 0.95rem;
}
.auth-points span {
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.1);
  display: grid; place-items: center; flex: none;
}

.auth-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 40px;
}

.auth-card {
  width: min(100%, 480px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px 22px 24px;
  animation: rise 480ms ease both;
}

.auth-card h1 { margin-bottom: 4px; }
.auth-card .lede { margin-bottom: 24px; font-size: 0.95rem; }

.form-grid {
  display: grid;
  gap: 14px;
}

.form-grid.two {
  grid-template-columns: 1fr;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--navy-800);
}
.req { color: var(--danger); }

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 13px;
  font: inherit;
  min-height: 46px;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.field textarea { min-height: 92px; resize: vertical; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.field input[aria-invalid="true"],
.field select[aria-invalid="true"] {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.hint, .error {
  font-size: 0.78rem;
  margin: 0;
}
.error { color: var(--danger); }
.hint { color: var(--text-muted); }

.input-row {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 8px;
}

.password-wrap { position: relative; }
.password-wrap input { padding-right: 46px; }
.toggle-visibility {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
}
.toggle-visibility:hover { background: var(--surface-muted); color: var(--text); }

.strength {
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.strength span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--border-strong);
  transition: width 220ms ease, background 220ms ease;
}
.strength.s1 span { width: 25%; background: #d92d20; }
.strength.s2 span { width: 50%; background: #dc6803; }
.strength.s3 span { width: 75%; background: #3b82f6; }
.strength.s4 span { width: 100%; background: #12b76a; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 180ms ease, background 180ms ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.65; cursor: not-allowed; transform: none; }
.btn-primary {
  background: linear-gradient(180deg, #2f6ff0, var(--blue-600));
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
  width: 100%;
}
.btn-primary:hover { filter: brightness(1.04); }
.btn-secondary {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #fecdca; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 0.88rem; width: auto; }

.checkbox {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.checkbox input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--blue-600); }

.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
  margin: 4px 0 8px;
}

.form-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecdca;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.88rem;
}

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(var(--sidebar), 86vw);
  background: var(--navy-900);
  color: #d7e3f5;
  z-index: 40;
  transform: translateX(-105%);
  transition: transform 240ms ease;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.sidebar.open { transform: translateX(0); }
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 22px;
  color: #fff;
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar nav { display: grid; gap: 8px; margin-top: 14px; }
.sidebar nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  color: #c9d7eb;
  text-decoration: none;
  font-weight: 500;
  transition: background 160ms ease, color 160ms ease;
}
.sidebar nav a:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
  text-decoration: none;
}
.sidebar nav a.active {
  background: linear-gradient(90deg, rgba(59,110,240,0.34), rgba(109,90,230,0.20));
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.sidebar nav a.active::before {
  content: "";
  position: absolute;
  left: 0; top: 9px; bottom: 9px;
  width: 3px;
  border-radius: 99px;
  background: #8fb0ff;
}
.sidebar .spacer { flex: 1; }

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 20, 39, 0.45);
  z-index: 30;
}
.backdrop.show { display: block; }

.content-wrap { min-width: 0; }

.topbar {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 25;
  height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(11, 31, 58, 0.03), 0 6px 16px rgba(11, 31, 58, 0.04);
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.logo-slot { width: 46px; height: 46px; flex: none; }
.logo-chip, .logo-placeholder {
  width: 46px; height: 46px; border-radius: 12px; flex: none;
  border: 1px solid var(--border);
}
.logo-chip { object-fit: contain; background: #fff; padding: 2px; }
.logo-placeholder {
  display: grid; place-items: center;
  background: linear-gradient(135deg, #e8eef8, #f4f0ff);
  color: var(--navy-700);
  font-weight: 700;
}

/* Company name: Arabic on line 1, English on line 2 */
.brand-names {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  min-width: 0;
  line-height: 1.3;
}
.brand-names [hidden] { display: none; }
.brand-names .name-ar {
  font-family: var(--arabic);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-align: left;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-names .name-en {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-names.big .name-ar { font-size: 1.35rem; }
.brand-names.big .name-en { font-size: 0.98rem; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  display: grid; place-items: center;
  color: var(--navy-800);
}

.icon-btn.avatar {
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-500), var(--violet-500));
  border: 0;
  color: #fff;
  font-weight: 700;
}
.menu-user {
  padding: 8px 12px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.menu {
  position: relative;
}
.menu-panel {
  display: none;
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 200px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
}
.menu-panel.open { display: block; }
.menu-panel a, .menu-panel button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-muted); }

.content {
  padding: 20px 16px 48px;
  max-width: 1120px;
  margin: 0 auto;
  animation: rise 420ms ease both;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.crumbs a { color: var(--text-muted); }
.crumbs span { color: var(--text); font-weight: 600; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { margin-bottom: 6px; }
.card .section-copy { margin-bottom: 16px; font-size: 0.9rem; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat small { color: var(--text-muted); display: block; margin-bottom: 6px; }
.stat strong { font-size: 1.15rem; }

.settings-grid {
  display: grid;
  gap: 12px;
}
.settings-link {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
  text-decoration: none;
  color: inherit;
}
.settings-link:hover { border-color: #c5d4f0; box-shadow: var(--shadow-sm); text-decoration: none; }
.settings-link .ico {
  width: 42px; height: 42px; border-radius: 12px;
  background: #eef3fb; display: grid; place-items: center; color: var(--navy-800);
}

.progress {
  height: 8px;
  background: #e6ebf3;
  border-radius: 99px;
  overflow: hidden;
  margin: 8px 0 18px;
}
.progress b {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue-600), var(--violet-500));
  border-radius: inherit;
  transition: width 400ms ease;
}

.steps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}
.step {
  background: var(--surface-muted);
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}
.step.done { background: #e7f0ff; color: var(--navy-800); }

.logo-uploader {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}
.logo-preview {
  width: 96px; height: 96px; border-radius: 20px;
  border: 1px dashed var(--border-strong);
  background: var(--surface-muted);
  display: grid; place-items: center; overflow: hidden;
}
.logo-preview { flex: none; }
.logo-preview img { width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 4px; }
.logo-side { display: grid; gap: 10px; min-width: 0; flex: 1; }
.logo-side .hint { margin: 0; }
.logo-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.rtl-field input, .rtl-field textarea {
  direction: rtl;
  text-align: right;
  font-family: var(--arabic);
}

.actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}
.actions-bar .btn { width: auto; }

.toasts {
  position: fixed;
  right: 16px;
  top: calc(var(--topbar) + 12px);
  z-index: 80;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}
.toast {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue-600);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  animation: rise 280ms ease both;
  font-size: 0.9rem;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--violet-500); }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }

.dir-ar { font-family: var(--arabic); }

@media (min-width: 768px) {
  .auth-card { padding: 36px 34px; }
  .form-grid.two { grid-template-columns: 1fr 1fr; }
  .steps { grid-template-columns: repeat(4, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 28px 28px 64px; }
}

@media (min-width: 1024px) {
  .auth-shell { grid-template-columns: minmax(320px, 42%) 1fr; }
  .auth-brand { display: flex; flex-direction: column; justify-content: center; }
  .sidebar { transform: none; }
  .icon-btn.menu-toggle { display: none; }
  .content-wrap { margin-left: var(--sidebar); }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1440px) {
  .content { max-width: 1200px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ===== Customers module ===== */
.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head-row .btn { width: auto; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  vertical-align: middle;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.tag-required { background: #eef3ff; color: var(--blue-600); border-color: #d6e2ff; }

.choice-group { display: flex; flex-wrap: wrap; gap: 10px; }
.choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 500;
  cursor: pointer;
}
.choice input { accent-color: var(--blue-600); width: 16px; height: 16px; margin: 0; }
.choice:has(input:checked) { border-color: var(--blue-600); background: #f3f7ff; }

.form-grid .span-2 { grid-column: 1 / -1; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.toolbar input[type="search"], .toolbar select {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  font: inherit;
  color: var(--text);
}
.toolbar input[type="search"] { flex: 1 1 240px; min-width: 200px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.data-table th, .data-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th { background: var(--surface-muted); color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fafbff; }
.data-table .col-actions { text-align: right; }
.data-table td.col-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.inline-form { display: inline; margin: 0; }
.muted { color: var(--text-muted); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 0.78rem; font-weight: 600; }
.badge-blue { background: #eef3ff; color: var(--blue-600); }
.badge-violet { background: #f3f0ff; color: var(--violet-500); }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-gray { background: #f1f3f7; color: var(--text-muted); }

.empty-state { text-align: center; padding: 40px 16px; }
.empty-state p { margin: 6px 0 16px; color: var(--text-muted); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; color: var(--text-muted); font-size: 0.9rem; }

/* ===== Salesmen, quotations, dialogs ===== */
.num { text-align: right; }
.cur { color: var(--text-muted); font-size: 0.78rem; font-weight: 600; margin-right: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.link-btn {
  align-self: flex-start;
  background: none;
  border: 0;
  padding: 2px 0;
  color: var(--blue-600);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.select-search {
  min-height: 38px !important;
  padding: 8px 12px !important;
  font-size: 0.9rem;
  background: var(--surface-muted) !important;
}

.issuer-box {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}
.issuer-logo {
  width: 52px; height: 52px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
  font-weight: 700;
  color: var(--navy-700);
}
.issuer-logo img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.name-en-strong { font-weight: 600; }

.lines-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.lines-table th {
  padding: 10px 10px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  text-align: left;
}
.lines-table th.num { text-align: right; }
.lines-table td { padding: 10px; vertical-align: top; border-bottom: 1px solid var(--border); }
.lines-table tbody tr:last-child td { border-bottom: 0; }
.lines-table .c-qty { width: 90px; }
.lines-table .c-price { width: 140px; }
.lines-table .c-vat { width: 100px; }
.lines-table .c-total { width: 130px; text-align: right; padding-top: 20px; font-weight: 600; white-space: nowrap; }
.lines-table .c-x { width: 44px; text-align: center; }
.lines-table textarea, .lines-table input, .lines-table select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 11px;
  min-height: 42px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
}
.lines-table textarea { resize: vertical; min-height: 42px; }
.lines-table textarea:focus, .lines-table input:focus, .lines-table select:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}
.lines-table [aria-invalid="true"] { border-color: var(--danger); background: var(--danger-bg); }
.lines-table .error { margin: 4px 0 0; font-size: 0.8rem; }
.icon-x {
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 4px;
}
.icon-x:hover { color: var(--danger); border-color: #fecdca; background: var(--danger-bg); }

.line-actions { display: flex; gap: 8px; margin-top: 14px; }

.totals-box { margin: 18px 0 0 auto; max-width: 340px; display: grid; gap: 8px; }
.totals-box > div { display: flex; justify-content: space-between; gap: 16px; }
.totals-box dt { color: var(--text-muted); }
.totals-box dd { margin: 0; font-weight: 600; }
.totals-box .grand { padding-top: 10px; border-top: 1px solid var(--border-strong); font-size: 1.08rem; }

/* ===== Quotation: discount toggle ===== */
.totals-wrap { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 18px; margin-top: 18px; }
.totals-wrap .totals-box { margin: 0 0 0 auto; flex: 0 1 340px; }
.totals-box > div[hidden] { display: none; }
.totals-box .discount-line dd { color: var(--success); }
.totals-box .discount-line:not([hidden]) { animation: total-line-in 220ms ease; }
@keyframes total-line-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.discount-box {
  flex: 0 1 320px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  transition: border-color 200ms ease, background-color 200ms ease, box-shadow 200ms ease;
}
.discount-box.is-on { border-color: #c7d7fb; background: #f6f9ff; box-shadow: 0 6px 18px rgba(37, 99, 235, 0.06); }

.switch { position: relative; display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.switch input[type="checkbox"] { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch-track {
  position: relative; flex-shrink: 0; width: 40px; height: 22px;
  border-radius: 999px; background: var(--border-strong);
  transition: background-color 200ms ease, box-shadow 200ms ease;
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(11, 31, 58, 0.25);
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.switch input:checked + .switch-track { background: var(--blue-600); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.18); }
.switch-text { display: flex; flex-direction: column; line-height: 1.25; }
.switch-text strong { color: var(--navy-800); font-size: 0.95rem; }
.switch-text small { color: var(--text-muted); font-size: 0.78rem; }

.discount-field {
  display: grid; grid-template-rows: 0fr; opacity: 0;
  transition: grid-template-rows 250ms ease, opacity 200ms ease, margin-top 250ms ease;
}
.discount-box.is-on .discount-field { grid-template-rows: 1fr; opacity: 1; margin-top: 12px; }
.discount-field-inner { min-height: 0; overflow: hidden; padding: 4px; margin: -4px; }
.totals-box .grand dt { color: var(--text); font-weight: 700; }

.stamp-block { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.stamp-block h3 { margin: 0 0 4px; font-size: 1.02rem; }

dialog.modal {
  width: min(440px, calc(100vw - 32px));
  padding: 24px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(11, 31, 58, 0.28);
}
dialog.modal::backdrop { background: rgba(11, 31, 58, 0.45); }
dialog.modal h2 { margin: 0 0 4px; }
dialog.modal .field { margin-top: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal-actions .btn { width: auto; }

/* ===== Sidebar: Settings dropdown ===== */
.sidebar nav details.nav-group { display: block; }
.sidebar nav details.nav-group > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  color: #c9d7eb;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 160ms ease, color 160ms ease;
}
.sidebar nav details.nav-group > summary::-webkit-details-marker { display: none; }
.sidebar nav details.nav-group > summary::marker { content: ""; }
.sidebar nav details.nav-group > summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 180ms ease;
  opacity: 0.8;
}
.sidebar nav details.nav-group[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }
.sidebar nav details.nav-group > summary:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav details.nav-group.has-active > summary { color: #fff; font-weight: 600; }
.sidebar nav details.nav-group > summary:focus-visible { outline: 2px solid #8fb0ff; outline-offset: 2px; }
.sidebar nav .nav-sub {
  display: grid;
  gap: 4px;
  margin: 6px 0 2px 16px;
  padding-left: 10px;
  border-left: 1px solid rgba(255,255,255,0.14);
}
.sidebar nav .nav-sub a { padding: 9px 12px; font-size: 0.93rem; }
