:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Arial, "Noto Sans Hebrew", sans-serif;
  --page-bg:
    radial-gradient(circle at 12% 8%, rgba(96, 165, 250, .22), transparent 30%),
    radial-gradient(circle at 88% 12%, rgba(34, 197, 94, .14), transparent 28%),
    linear-gradient(145deg, #0b0f14, #111827 58%, #0f172a);
  --text: #f8fafc;
  --muted: #94a3b8;
  --soft: #cbd5e1;
  --panel: linear-gradient(180deg, rgba(17, 24, 39, .92), rgba(15, 23, 42, .86));
  --button: rgba(15, 23, 42, .82);
  --surface: rgba(255, 255, 255, .045);
  --surface-strong: rgba(15, 23, 42, .72);
  --border: rgba(148, 163, 184, .18);
  --field: rgba(15, 23, 42, .86);
  --modal: #111827;
  background: #0b0f14;
  color: var(--text);
}

:root[data-theme="light"] {
  color-scheme: light;
  --page-bg:
    radial-gradient(circle at 12% 8%, rgba(37, 99, 235, .13), transparent 30%),
    radial-gradient(circle at 88% 12%, rgba(34, 197, 94, .12), transparent 28%),
    linear-gradient(145deg, #f8fafc, #eef6ff 58%, #f1f5f9);
  --text: #0f172a;
  --muted: #64748b;
  --soft: #334155;
  --panel: linear-gradient(180deg, rgba(255, 255, 255, .96), rgba(248, 250, 252, .92));
  --button: rgba(255, 255, 255, .88);
  --surface: rgba(15, 23, 42, .045);
  --surface-strong: rgba(255, 255, 255, .72);
  --border: rgba(71, 85, 105, .18);
  --field: rgba(255, 255, 255, .94);
  --modal: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page-bg);
  color: var(--text);
}

body[data-mode="admin"] {
  --page-bg: linear-gradient(145deg, #0b0f14, #111827 58%, #0f172a);
}

body[data-mode="employee"] {
  --page-bg:
    radial-gradient(circle at 18% 0%, rgba(34, 197, 94, .16), transparent 28%),
    radial-gradient(circle at 86% 12%, rgba(37, 99, 235, .18), transparent 30%),
    linear-gradient(145deg, #07111f, #111827 58%, #0f172a);
}

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

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.app {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar,
.toolbar,
.calendar-head,
.panel-head,
.employee-row,
.stat-row,
.issue-row {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.topbar p {
  margin: 0 0 4px;
  color: #93c5fd;
  font-weight: 800;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 4.8rem);
  line-height: .95;
}

.home-link,
.sync-pill,
.primary,
.secondary,
.icon,
.button-link {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, .22);
  color: var(--text);
  font-weight: 800;
}

.home-link {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  background: rgba(255, 255, 255, .06);
  text-decoration: none;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  background: rgba(255, 255, 255, .06);
  color: #cbd5e1;
}

.sync-pill.ok { color: #86efac; }
.sync-pill.bad { color: #fca5a5; }

.toolbar {
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar-main,
.action-menu > div {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.action-menu {
  position: relative;
}

.action-menu summary {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 12px;
  background: var(--button);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.action-menu summary::-webkit-details-marker {
  display: none;
}

.action-menu > div {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  width: min(320px, calc(100vw - 36px));
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--modal);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .34);
}

.action-menu > div > * {
  width: 100%;
  justify-content: center;
}

.ghost-action {
  display: none !important;
}

.primary,
.secondary,
.icon {
  padding: 0 14px;
}

.primary {
  border: 0;
  background: linear-gradient(135deg, #2563eb, #22c55e);
  box-shadow: 0 14px 30px rgba(37, 99, 235, .25);
}

.secondary,
.icon {
  background: var(--button);
}

.button-link {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  text-decoration: none;
}

.secondary.danger {
  border-color: rgba(248, 113, 113, .32);
  color: #fecaca;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.dashboard-cards,
.employee-dashboard {
  display: grid;
  gap: 12px;
}

.dashboard-cards {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-card {
  min-height: 98px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.metric-card span,
.metric-card small {
  color: var(--muted);
  font-weight: 800;
  font-size: .82rem;
}

.metric-card strong {
  font-size: 1.7rem;
  line-height: 1;
}

.metric-card.ok {
  border-color: rgba(34, 197, 94, .34);
}

.metric-card.warn {
  border-color: rgba(245, 158, 11, .42);
}

.employee-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  min-height: 136px;
  padding: 18px;
  border: 1px solid rgba(96, 165, 250, .24);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(37, 99, 235, .26), rgba(34, 197, 94, .12));
}

.employee-hero div,
.employee-hero strong,
.employee-hero span,
.employee-hero small {
  display: block;
}

.employee-hero span,
.employee-hero small {
  color: var(--muted);
  font-weight: 800;
}

.employee-hero strong {
  margin: 6px 0;
  font-size: 2.2rem;
  line-height: 1;
}

.employee-quick-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.my-shifts-panel {
  box-shadow: none;
}

.my-shifts-list {
  display: grid;
  gap: 8px;
}

.my-shift-row {
  min-height: 54px;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: start;
}

.my-shift-row small {
  color: var(--muted);
}

.panel {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .24);
  padding: 14px;
}

.panel-head {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.compact-field {
  margin-bottom: 12px;
}

.compact-field input {
  min-height: 40px;
}

.panel-head h2,
.calendar-head h2 {
  margin: 0;
}

.panel-head span,
.calendar-head p,
.muted {
  color: var(--muted);
  font-size: .88rem;
}

.employees-list,
.issues-list,
.stats-list {
  display: grid;
  gap: 9px;
}

.employees-list {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.employee-row {
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.employee-main {
  min-width: 0;
}

.employee-main strong,
.employee-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.employee-main span {
  color: var(--muted);
  font-size: .82rem;
}

.employee-actions {
  display: flex;
  gap: 6px;
}

.mini {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 10px;
}

.calendar-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  text-align: center;
}

.role-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  margin-bottom: 8px;
  scrollbar-width: thin;
}

.role-tab {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.role-tab.active {
  border-color: rgba(37, 99, 235, .55);
  background: linear-gradient(135deg, rgba(37, 99, 235, .88), rgba(34, 197, 94, .72));
  color: #fff;
}

.icon {
  width: 46px;
  padding: 0;
  font-size: 1.5rem;
}

.calendar-boards {
  display: grid;
  gap: 16px;
}

.calendar-boards.multi {
  grid-template-columns: minmax(0, 1fr);
}

.month-board {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, .025);
}

.month-board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.month-board-head h3 {
  margin: 0;
  font-size: 1rem;
}

.month-board-head span {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
}

.dow,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.dow {
  margin-bottom: 8px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.day {
  min-height: 136px;
  display: grid;
  align-content: start;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.day.out {
  opacity: .42;
}

.day.today {
  border-color: #60a5fa;
}

.day-head {
  display: flex;
  justify-content: space-between;
  color: var(--soft);
  font-weight: 800;
  font-size: .82rem;
}

.assignment {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 7px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-strong);
}

.note-dot {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: rgba(250, 204, 21, .2);
  color: #fde68a;
  font-weight: 900;
  font-size: .8rem;
}

.assignment strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .78rem;
}

.shift {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  font-weight: 900;
}

.shift.M { background: rgba(34, 197, 94, .28); color: #bbf7d0; }
.shift.E { background: rgba(245, 158, 11, .28); color: #fde68a; }
.shift.N { background: rgba(167, 139, 250, .28); color: #ddd6fe; }
.shift.O { background: rgba(100, 116, 139, .34); color: #e2e8f0; }
.shift.V { background: rgba(239, 68, 68, .24); color: #fecaca; }
.shift.override {
  outline: 2px solid rgba(248, 113, 113, .55);
}

.issue-row,
.stat-row {
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface);
}

.issue-row.bad { border: 1px solid rgba(239, 68, 68, .28); }
.issue-row.ok { border: 1px solid rgba(34, 197, 94, .24); }

.stats-title {
  margin-top: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .58);
}

.modal-backdrop.show {
  display: flex;
}

.modal {
  width: min(760px, 100%);
  max-height: min(92vh, 860px);
  overflow: auto;
  padding: 16px;
  border: 1px solid rgba(148, 163, 184, .2);
  border-radius: 18px;
  background: var(--modal);
}

.modal h3 {
  margin: 0 0 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: .85rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 12px;
  outline: none;
  background: var(--field);
  color: var(--text);
}

.field textarea {
  min-height: 86px;
  padding-top: 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(440px, 100%);
  margin: 12vh auto 0;
}

.login-card h1 {
  margin: 0;
  font-size: clamp(2.4rem, 8vw, 4.6rem);
  line-height: .95;
}

.login-error {
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(239, 68, 68, .28);
  border-radius: 12px;
  background: rgba(239, 68, 68, .14);
  color: #fecaca;
}

.modal-note {
  margin: 0 0 12px;
}

.login-list {
  display: grid;
  gap: 9px;
}

.login-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.3fr) minmax(130px, 1fr) minmax(110px, .8fr) auto;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.login-row div {
  min-width: 0;
}

.login-row strong,
.login-row span {
  display: block;
  overflow-wrap: anywhere;
}

.login-row span {
  color: var(--muted);
  font-size: .82rem;
}

@media (max-width: 820px) {
  .topbar {
    display: grid;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
  }

  .toolbar-main,
  .employee-toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar-main > *,
  .employee-toolbar > *,
  .action-menu,
  .action-menu summary {
    width: 100%;
    justify-content: center;
  }

  .action-menu > div {
    position: static;
    width: 100%;
    margin-top: 8px;
  }

  .dashboard-cards,
  .employee-quick-grid {
    grid-template-columns: 1fr;
  }

  .employee-hero {
    display: grid;
  }

  .employee-hero strong {
    font-size: 1.8rem;
  }

  .employees-list {
    grid-template-columns: 1fr;
  }

  .dow,
  .calendar-grid {
    grid-template-columns: 1fr;
  }

  .dow {
    display: none;
  }

  .calendar-boards.multi {
    grid-template-columns: 1fr;
  }

  .day {
    min-height: auto;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .login-row {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1100px) {
  body[data-mode="admin"] .calendar-panel {
    padding: 16px;
  }

  body[data-mode="admin"] .day {
    min-height: 126px;
  }

  body[data-mode="employee"] .calendar-panel {
    order: 2;
  }

  body[data-mode="employee"] .employee-dashboard {
    order: 1;
  }
}
