:root {
  --accent: #16a34a;
  --accent-dark: #15803d;
  --accent-soft: #dcfce7;
  --accent-faint: #f0fdf4;
  --bg: #eceef1;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --neg: #b91c1c;
  --nav: #c62828;
  --nav-dark: #a31f1f;
  --note: #f8f1d8;
  --note-border: #e6d498;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 1px 3px rgb(0 0 0 / 0.06);
  --shadow-lg: 0 10px 30px rgb(0 0 0 / 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

/* always keep room for the scrollbar, so short and long pages line up */
html { scrollbar-gutter: stable; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

button, input, select { font: inherit; color: inherit; }

a { color: var(--accent-dark); text-decoration: none; }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* numbers and dates keep their left to right order in hebrew */
.ltr, .price, .date-input, .note-title small { direction: ltr; unicode-bidi: isolate; }
.spacer { flex: 1; }

.icon { display: inline-flex; width: 18px; height: 18px; flex-shrink: 0; }
.icon svg { width: 100%; height: 100%; }

/* ---------- navbar ---------- */

#nav:empty { display: none; }

#nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 20px;
  background: var(--nav);
  color: #fff;
}

.login-logo {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.nav-links {
  display: flex;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: var(--radius);
  color: rgb(255 255 255 / 0.8);
  font-weight: 500;
  white-space: nowrap;
}

.nav-links a:hover { background: var(--nav-dark); color: #fff; }
.nav-links a.active { background: #fff; color: var(--nav); }

/* on the red bar: white logo, translucent controls */
#nav .avatar { box-shadow: 0 0 0 2px rgb(255 255 255 / 0.85); }
#nav .icon-button { color: #fff; }
#nav .icon-button:hover { background: var(--nav-dark); color: #fff; }
#nav .lang { background: var(--nav-dark); border-color: rgb(255 255 255 / 0.35); color: #fff; }
#nav .lang option { background: #fff; color: var(--text); }

.nav-user { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.nav-user .lang { width: auto; padding-block: 4px; }
.user-name { font-weight: 500; }

@media (max-width: 1100px) {
  .nav-links a span:not(.icon) { display: none; }
}

@media (max-width: 640px) {
  #nav { gap: 8px; padding: 0 12px; }
  .user-name { display: none; }
  main { padding: 12px; }
  .toolbar > .input, .toolbar > .ac, .toolbar > .ms-button { width: 100%; max-width: none; }
}

/* ---------- layout ---------- */

main { padding: 20px; max-width: 1600px; margin: 0 auto; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar h1 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  margin-inline-end: 4px;
  font-size: 18px;
  font-weight: 650;
  white-space: nowrap;
}

.toolbar h1 .icon { color: var(--accent); width: 20px; height: 20px; }
.toolbar > .input { width: 150px; }
.toolbar > .ac { width: 150px; min-width: 0; }
.toolbar > .ms-button { width: 130px; min-width: 0; }
.toolbar .daterange .datepicker.with-time { width: 180px; }
.toolbar > .muted { margin-inline-end: 8px; white-space: nowrap; }

.page-actions { display: flex; gap: 8px; margin-inline-start: auto; }

.totals { display: flex; gap: 12px; margin-inline-end: 8px; padding-inline-end: 12px; border-inline-end: 1px solid var(--border); color: var(--muted); font-size: 13px; white-space: nowrap; }
.totals:empty { display: none; }
.totals b { color: var(--text); font-size: 14px; }

/* ---------- controls ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.button:hover:not(:disabled) { background: var(--bg); }
.button:disabled { opacity: 0.45; cursor: default; }
.button.small { height: 28px; padding: 0 10px; font-size: 13px; }
.button.block { width: 100%; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover:not(:disabled) { background: var(--accent-dark); }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.danger:hover { background: #b91c1c; }
.button.danger-outline { color: var(--danger); border-color: #fca5a5; }
.button.danger-outline:hover { background: var(--danger-soft); }
.button .icon { width: 16px; height: 16px; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-dark);
  font-weight: 500;
  cursor: pointer;
}

.link:hover { text-decoration: underline; }

.input, .select, .ac-input, .date-input, .ms-button {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus, .select:focus, .ac-input:focus, .date-input:focus, .ms-button:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(22 163 74 / 0.15);
}

.input::placeholder, .ac-input::placeholder, .date-input::placeholder { color: var(--faint); }
.select.empty { color: var(--faint); }
.select option { color: var(--text); }
input:disabled, select:disabled { background: var(--bg); color: var(--muted); }

.invalid, .invalid .ac-input, .input.invalid, .date-input.invalid { border-color: var(--danger) !important; }

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button { opacity: 0.4; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* autocomplete */
.ac { position: relative; display: flex; align-items: center; min-width: 150px; }
.ac-prefix { position: absolute; inset-inline-start: 6px; display: flex; pointer-events: none; }
.ac-prefix:empty { display: none; }
.ac.has-prefix .ac-input { padding-inline-start: 36px; }
.ac-list { max-height: 280px; overflow-y: auto; padding: 4px; }
.ac-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.ac-item small { margin-inline-start: auto; padding-inline-start: 12px; color: var(--muted); }
.ac-item.active { background: var(--accent-soft); }
.ac-empty { padding: 8px; color: var(--muted); }

/* multiselect */
.ms-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 130px;
  max-width: 220px;
  text-align: start;
  cursor: pointer;
}
.ms-button span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-button.empty { color: var(--faint); }
.caret { border: 4px solid transparent; border-top-color: var(--muted); margin-top: 4px; }
.ms-list { padding: 4px; max-height: 300px; overflow-y: auto; }
.ms-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.ms-item:hover { background: var(--bg); }

/* datepicker */
/* date fields keep the left to right layout in hebrew too: text on the left, calendar icon on the right */
.datepicker { position: relative; display: inline-flex; align-items: center; width: 140px; direction: ltr; }
.datepicker.with-time { width: 180px; }
.date-input { padding-inline-end: 32px; font-variant-numeric: tabular-nums; }
.calendar-button { position: absolute; inset-inline-end: 2px; width: 28px; height: 28px; }
.calendar-button .icon { width: 16px; height: 16px; }
.daterange { display: inline-flex; align-items: center; gap: 4px; }
.calendar { padding: 10px; width: 260px; }
.calendar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.calendar-time { display: flex; align-items: center; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); direction: ltr; }
.calendar-time .icon { color: var(--muted); }
.calendar-time .select { width: auto; height: 30px; padding: 0 6px; font-variant-numeric: tabular-nums; }
.calendar-time .button { margin-inline-start: auto; }
.weekday { color: var(--muted); font-size: 12px; padding: 4px 0; }
.day { height: 32px; border: 0; border-radius: 6px; background: none; cursor: pointer; font-variant-numeric: tabular-nums; }
.day:hover { background: var(--bg); }
.day.other { color: var(--faint); }
.day.today { box-shadow: inset 0 0 0 1px var(--accent); }
.day.selected { background: var(--accent); color: #fff; }
.flip.rotate .icon, [dir="rtl"] .flip:not(.rotate) .icon { transform: rotate(180deg); }
[dir="rtl"] .flip.rotate .icon { transform: none; }

/* popup */
.popup {
  position: fixed;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

/* ---------- avatar ---------- */

.avatar {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
}

.client { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }

/* ---------- list ---------- */

.bulk {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 3px;
  padding-inline-start: 10px;
  background: var(--accent-faint);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
  white-space: nowrap;
}

.bulk.visible { display: flex; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table.list { width: 100%; border-collapse: collapse; }

table.list th, table.list td {
  padding: 8px 10px;
  text-align: start;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.list th {
  position: sticky;
  top: 0;
  background: #fafafa;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  user-select: none;
}

table.list th.sortable { cursor: pointer; }
table.list th.sortable:hover { color: var(--text); }
table.list th.sorted { color: var(--accent-dark); }
table.list th.sorted::after { content: " ▲"; font-size: 9px; }
table.list th.sorted.desc::after { content: " ▼"; }

table.list tbody tr:last-child td { border-bottom: 0; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--accent-faint); }
table.list tr.empty td { padding: 32px; text-align: center; color: var(--muted); }

table.list .check { width: 36px; }
table.list td.id, .id { color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; width: 40px; }
table.list td.id .icon { width: 14px; height: 14px; color: var(--accent); }
table.list .row-action { width: 70px; }
td.col-price, td.col-int { font-variant-numeric: tabular-nums; white-space: nowrap; }

table.list tr.new-row td { background: var(--accent-faint); padding-block: 6px; }
table.list tr.new-row .input, table.list tr.new-row .select { min-width: 80px; }
table.list tr.new-row .datepicker { width: 180px; }

.price { font-variant-numeric: tabular-nums; }
.price.neg { color: var(--neg); }
.price.pos { color: var(--accent-dark); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--bg); color: var(--muted); }
.badge-new { background: #fef3c7; color: #92400e; }
.badge-done { background: var(--accent-soft); color: var(--accent-dark); }
.badge-admin { background: #ede9fe; color: #5b21b6; }

@keyframes flash {
  from { background: #86efac; }
  to { background: transparent; }
}

table.list tr.flash td { animation: flash 2s ease-out; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 2px;
}

.pager-nav { display: flex; align-items: center; gap: 6px; }
.pager-nav span { padding: 0 8px; white-space: nowrap; }
.page-size { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.page-size .select { width: auto; height: 28px; }

/* ---------- modal ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(17 24 39 / 0.35);
}

.modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}

.modal.small { max-width: 400px; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 8px; }
.modal h2 { margin: 0; font-size: 17px; }
.modal h2 .id { font-weight: 400; }
.modal-body { padding: 8px 20px; overflow-y: auto; }
.modal-body p { margin: 4px 0 12px; }
.modal footer { display: flex; gap: 8px; padding: 12px 20px 16px; }

.form { display: grid; gap: 12px; }
.form-field { display: grid; gap: 4px; }
.form-field > span { font-size: 13px; font-weight: 500; color: var(--muted); }
.form-field .datepicker, .form-field .ac { width: 100%; }
.field-error { color: var(--danger); font-size: 12px; }
.field-error:empty { display: none; }

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  bottom: 20px;
  inset-inline-end: 20px;
  z-index: 200;
  display: grid;
  gap: 8px;
}

.toast {
  max-width: 380px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.4s, transform 0.4s;
}

.toast.error { background: var(--danger); }
.toast.success { background: var(--accent-dark); }
.toast.hide { opacity: 0; transform: translateY(8px); }

/* ---------- login ---------- */

.login { display: grid; place-items: center; min-height: calc(100vh - 40px); }

.login-card {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 340px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; }
.login-logo { width: 44px; height: 44px; margin: 0 auto; border-radius: 12px; font-size: 22px; }
.login-error { color: var(--danger); min-height: 1em; font-size: 13px; }

/* ---------- notes board ---------- */

.add-line > .ac { width: 160px; }
.add-line > .input[type="number"] { width: 70px; }
.add-line > .input:not([type="number"]) { flex: 1; min-width: 100px; }
.new-note { display: flex; align-items: center; gap: 6px; padding: 0 4px; color: var(--muted); white-space: nowrap; cursor: pointer; }

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  align-items: start;
}

.note {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--note);
  border: 1px solid var(--note-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.note-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  padding-inline-end: 18px;
  border-bottom: 1px dashed var(--note-border);
}

/* client and date on one line: a long name is cut, the date stays whole */
.note-title { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.note-title .client { min-width: 0; }
.note-title .client-name { overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.note-title small { flex-shrink: 0; margin-inline-start: auto; font-size: 12px; font-variant-numeric: tabular-nums; }

/* small circle overlapping the note's top end corner (top right, top left in rtl) */
.buzzer {
  position: absolute;
  top: -9px;
  inset-inline-end: -9px;
  z-index: 1;
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 5px;
  border: 2px solid var(--bg);
  border-radius: 999px;
  background: var(--muted);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow);
}
.dismiss:hover { color: var(--accent-dark) !important; background: var(--accent-soft) !important; }

.note-lines { display: grid; gap: 2px; min-height: 44px; padding: 6px; }

.line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgb(255 255 255 / 0.7);
  cursor: grab;
}

.line:hover { background: #fff; }
.line .qty { min-width: 22px; font-weight: 700; color: var(--accent-dark); font-variant-numeric: tabular-nums; }
.line .line-text { display: grid; flex: 1; min-width: 0; }
.line .line-text small { color: var(--muted); }
.line .served { width: 20px; height: 20px; flex-shrink: 0; }
.line .price { font-size: 12px; }
.line.done .line-text span, .line.done .qty { text-decoration: line-through; color: var(--faint); }
.line-delete { width: 26px; height: 26px; }
.line-delete:hover:not(:disabled) { color: var(--danger) !important; background: var(--danger-soft) !important; }
.line-delete:disabled { opacity: 0.3; cursor: not-allowed; }
.line-delete .icon { width: 14px; height: 14px; }


@keyframes glow {
  0%, 30% { background: #bbf7d0; box-shadow: 0 0 0 3px #4ade80; }
  100% { background: rgb(255 255 255 / 0.7); box-shadow: 0 0 0 3px transparent; }
}

.line.glow { animation: glow 2.5s ease-out; }


/* ---------- drag and drop ---------- */

.drag-handle { touch-action: none; user-select: none; }
.note-head.drag-handle { cursor: grab; }
.dragging { display: none !important; }
.is-dragging, .is-dragging * { cursor: grabbing !important; user-select: none; }

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 300;
  pointer-events: none;
  opacity: 0.92;
  box-shadow: var(--shadow-lg);
  transform-origin: top left;
}

.drag-placeholder {
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: var(--accent-faint);
}
