*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
html, body {
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}
.header {
  text-align: center;
  padding: 18px 0 10px;
}
.header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #1565c0;
}
.header .sub {
  font-size: 0.85rem;
  color: #666;
  margin-top: 2px;
}
.status-bar {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 -16px 8px;
  padding: 8px 16px;
  background: rgba(245, 245, 245, 0.94);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid #e0e0e0;
}
@media (max-width: 420px) {
  .status-bar { margin: 0 -10px 8px; padding: 6px 10px; }
}
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 1px solid #dfe3e8;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #333;
  direction: ltr;
  unicode-bidi: isolate;
}
.status-chip[hidden] { display: none; }
.status-chip.clock {
  font-family: 'Courier New', monospace;
  font-size: 1.05rem;
  color: #1565c0;
  letter-spacing: 0.5px;
}
.status-chip.date { font-weight: 600; color: #555; direction: rtl; }
.status-chip.low {
  background: #ffebee;
  border-color: #ef9a9a;
  color: #c62828;
  animation: pulse-low-battery 1.4s infinite ease-in-out;
}
@keyframes pulse-low-battery {
  0%, 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0.35); }
  50%      { box-shadow: 0 0 0 6px rgba(198, 40, 40, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .status-chip.low { animation: none; }
}
.banner {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 10px 16px;
  margin: 8px 0 14px;
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  transition: background 0.25s, opacity 0.3s;
}
.banner.idle {
  background: #e3f2fd;
  color: #444;
}
.banner.loading {
  background: #fff3e0;
  color: #e65100;
}
.banner.success {
  background: #e8f5e9;
  color: #2e7d32;
}
.banner.error {
  background: #ffebee;
  color: #c62828;
}
.banner.hidden {
  opacity: 0;
  pointer-events: none;
}
.sync-indicator {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #1565c0;
  background: #e8f1fb;
  border-radius: 10px;
  padding: 6px 10px;
  margin: -6px 0 10px;
}
.sync-indicator[hidden] { display: none; }
.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #777;
  margin: 10px 0 6px;
}
.workers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.worker-btn {
  background: #ffffff;
  border: 2px solid #e0e0e0;
  border-radius: 14px;
  padding: 14px 8px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s, color 0.2s, box-shadow 0.2s;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  word-break: break-word;
  touch-action: manipulation;
  position: relative;
}
.worker-btn:active {
  transform: scale(0.96);
}
.worker-btn.selected {
  background: #1565c0;
  border-color: #42a5f5;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.25);
}
.worker-btn.on-break {
  border-color: #f57c00;
  background: #fffbf7;
  box-shadow: 0 0 0 2px rgba(245, 124, 0, 0.2);
}
.worker-btn.on-break.selected {
  background: #1565c0;
  border-color: #ff9800;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.3);
}
.worker-btn .worker-name {
  display: block;
  line-height: 1.25;
}
.worker-btn.is-saving {
  border-color: #ef6c00 !important;
  background: #fff8e1 !important;
  animation: pulse-saving 1.2s infinite ease-in-out;
}
@keyframes pulse-saving {
  0% { box-shadow: 0 0 0 0 rgba(239, 108, 0, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(239, 108, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 108, 0, 0); }
}
.worker-btn-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-top: 4px;
  line-height: 1.2;
  direction: rtl;
  transition: background 0.3s, color 0.3s;
  animation: fade-in-badge 0.25s ease-out;
}
.worker-btn-status-badge.saving {
  background: #ef6c00;
  color: #ffffff;
}
.worker-btn-status-badge.success {
  background: #2e7d32;
  color: #ffffff;
}
.worker-btn-status-badge.error {
  background: #c62828;
  color: #ffffff;
}
.worker-btn-status-badge.queued {
  background: #1565c0;
  color: #ffffff;
}
.worker-btn.is-queued {
  border-color: #1565c0 !important;
  background: #e8f1fb !important;
}
.worker-btn-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-top: 4px;
  background: #ef6c00;
  color: #ffffff;
  line-height: 1.2;
  direction: ltr;
  transition: background 0.3s;
}
.actions-area {
  display: none;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
  margin-bottom: 20px;
}
.actions-area.visible {
  display: flex;
}
.actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.action-btn {
  border: none;
  border-radius: 14px;
  padding: 20px 10px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: filter 0.2s, transform 0.1s, opacity 0.2s;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  touch-action: manipulation;
  position: relative;
}
.action-btn:active {
  transform: scale(0.95);
}
.action-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.6);
}
.action-btn.is-recorded::after {
  content: '✓ مسجل';
  position: absolute;
  top: 7px;
  inset-inline-start: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  border-radius: 10px;
  padding: 2px 6px;
}
.action-btn.start         { background: #2e7d32; }
.action-btn.break-out     { background: #ef6c00; }
.action-btn.break-in      { background: #1565c0; }
.action-btn.end           { background: #c62828; }
.action-btn.emergency-out { background: #d84315; }
.action-btn.emergency-in  { background: #ad1457; }
.action-btn .emoji {
  display: block;
  font-size: 1.5rem;
  margin-bottom: 4px;
}
.selected-pill {
  background: #e3f2fd;
  border-radius: 30px;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  color: #1565c0;
  text-align: center;
  margin-bottom: 6px;
}
.selected-pill strong {
  color: #0d47a1;
}
.override-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid #ffcdd2;
  border-radius: 12px;
  background: #fff8f8;
}
.override-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #b71c1c;
  cursor: pointer;
}
.override-toggle input { width: 22px; height: 22px; accent-color: #c62828; }
.override-note {
  width: 100%;
  border: 1px solid #ef9a9a;
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  color: #333;
  background: #fff;
}
.override-note:disabled { opacity: 0.55; background: #f5f5f5; }
.clear-btn {
  background: none;
  border: 1px solid #bbb;
  border-radius: 30px;
  color: #555;
  padding: 8px 20px;
  font-size: 0.85rem;
  cursor: pointer;
  align-self: center;
  transition: background 0.2s, color 0.2s;
  margin-top: 4px;
  touch-action: manipulation;
}
.clear-btn:active {
  background: #e0e0e0;
  color: #222;
}
.controls-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.refresh-btn {
  background: #1565c0;
  border: none;
  border-radius: 30px;
  color: #fff;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  align-self: center;
  transition: background 0.2s, transform 0.1s;
  touch-action: manipulation;
}
.refresh-btn:active {
  background: #0d47a1;
  transform: scale(0.96);
}
.refresh-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}
.reload-btn {
  background: #ffffff;
  border: 1.5px solid #cccccc;
  border-radius: 30px;
  color: #333333;
  padding: 9px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  align-self: center;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  touch-action: manipulation;
}
.reload-btn:active {
  background: #e0e0e0;
  border-color: #bbbbbb;
  transform: scale(0.96);
}
.mt-auto {
  margin-top: auto;
}
.active-breaks-area {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.active-breaks-area.visible {
  display: flex;
}
.break-timer-card {
  background: #fff;
  border: 2px solid #e0e0e0;
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.break-timer-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.break-timer-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: #333;
}
.break-timer-since {
  font-size: 0.8rem;
  color: #888;
}
.break-timer-type {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1565c0;
  margin-top: 2px;
}
.break-timer-badge {
  border-radius: 30px;
  padding: 6px 12px;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  min-width: 80px;
  text-align: center;
  transition: background 0.5s ease, color 0.5s ease;
}
@media (max-width: 420px) {
  .app { padding: 10px; }
  .workers-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .actions-grid { gap: 8px; }
  .worker-btn { font-size: 1rem; padding: 12px 6px; min-height: 64px; }
  .action-btn { font-size: 0.95rem; padding: 16px 8px; min-height: 70px; }
}
@media (min-width: 600px) {
  .workers-grid { grid-template-columns: repeat(3, 1fr); }
}
.reward-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.reward-stack:empty {
  display: none;
}
.reward-card {
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  animation: fadeSlideUp 0.3s ease-out;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.reward-card.reward-success {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}
.reward-card.reward-error {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ef9a9a;
}
.reward-card.reward-info {
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
}
.reward-card .reward-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 2px 6px;
  border-radius: 6px;
  touch-action: manipulation;
  flex-shrink: 0;
}
.reward-card .reward-close:active {
  opacity: 1;
  background: rgba(0,0,0,0.08);
}
.reward-clear-all {
  background: none;
  border: 1px solid #ccc;
  border-radius: 20px;
  color: #888;
  padding: 6px 14px;
  font-size: 0.75rem;
  cursor: pointer;
  align-self: center;
  touch-action: manipulation;
  margin-top: 2px;
}
.reward-clear-all:active {
  background: #eee;
}
.fx-layer {
  position: fixed;
  left: 0;
  right: 0;
  top: 16%;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}
.fx-pop {
  position: relative;
  min-width: 210px;
  max-width: 88vw;
  text-align: center;
  padding: 12px 28px 14px;
  border-radius: 24px;
  color: #fff;
  font-weight: 800;
  will-change: transform, opacity;
  animation: fxFlyUp 2.8s cubic-bezier(.2, .8, .2, 1) forwards;
}
.fx-pop.plus {
  background: linear-gradient(135deg, #43a047, #1b5e20);
  box-shadow: 0 12px 34px rgba(46, 125, 50, 0.5), 0 0 0 3px rgba(255, 214, 0, 0.9), 0 0 28px rgba(255, 214, 0, 0.55);
}
.fx-pop.minus {
  background: linear-gradient(135deg, #e53935, #8e0000);
  box-shadow: 0 12px 34px rgba(198, 40, 40, 0.5), 0 0 0 3px rgba(255, 255, 255, 0.55);
  animation-name: fxDropDown;
}
.fx-name   { font-size: 0.85rem; opacity: 0.92; }
.fx-amount {
  font-size: 2.6rem;
  line-height: 1.15;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  direction: ltr;
  unicode-bidi: isolate;
}
.fx-label  { font-size: 0.9rem; opacity: 0.96; }
.fx-spark {
  position: absolute;
  left: 50%;
  top: 50%;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  animation: fxSpark 1.2s ease-out 0.08s forwards;
}
.fx-pop.plus  .fx-spark { color: #ffd600; text-shadow: 0 0 8px rgba(255, 214, 0, 0.9); }
.fx-pop.minus .fx-spark { color: #ffcdd2; }
@keyframes fxFlyUp {
  0%   { opacity: 0; transform: translateY(46px) scale(0.35); }
  12%  { opacity: 1; transform: translateY(0) scale(1.2); }
  22%  { opacity: 1; transform: translateY(-6px) scale(1); }
  78%  { opacity: 1; transform: translateY(-64px) scale(1); }
  100% { opacity: 0; transform: translateY(-150px) scale(0.92); }
}
@keyframes fxDropDown {
  0%   { opacity: 0; transform: translateY(-40px) scale(1.55); }
  10%  { opacity: 1; transform: translateX(0) scale(1.12); }
  14%  { transform: translateX(-12px) scale(1.08); }
  18%  { transform: translateX(12px) scale(1.06); }
  22%  { transform: translateX(-7px) scale(1.02); }
  26%  { transform: translateX(0) scale(1); }
  78%  { opacity: 1; transform: translateY(10px) scale(1); }
  100% { opacity: 0; transform: translateY(46px) scale(0.92); }
}
@keyframes fxSpark {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.3); }
}
@keyframes fxFade {
  0%, 100% { opacity: 0; }
  15%, 80% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .fx-pop, .fx-pop.minus { animation-name: fxFade; }
  .fx-spark { display: none; }
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in {
  animation: fadeSlideUp 0.3s ease-out;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
  animation: fadeSlideUp 0.2s ease-out;
}
.modal-overlay.hidden {
  display: none;
}
.modal-card {
  background: #fff;
  border-radius: 18px;
  padding: 22px 20px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
.modal-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
}
.modal-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #c62828;
  margin-bottom: 8px;
}
.modal-message {
  font-size: 0.9rem;
  color: #555;
  line-height: 1.5;
  margin-bottom: 6px;
}
.modal-existing-value {
  font-family: 'Courier New', monospace;
  font-weight: 800;
  font-size: 1.1rem;
  color: #333;
  background: #f5f5f5;
  border-radius: 10px;
  padding: 6px 14px;
  display: inline-block;
  margin: 6px 0 18px;
  unicode-bidi: plaintext;
}
.modal-actions {
  display: flex;
  gap: 10px;
}
.modal-btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: filter 0.2s, transform 0.1s;
}
.modal-btn:active {
  transform: scale(0.96);
}
.modal-btn.cancel {
  background: #f0f0f0;
  color: #555;
}
.modal-btn.confirm {
  background: #c62828;
  color: #fff;
}
.history-section {
  margin-top: 22px;
  padding-top: 10px;
  border-top: 1px solid #e0e0e0;
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-day-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-day-title {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 8px;
  margin-bottom: 1px;
}
.history-day-title .rel {
  font-size: 0.78rem;
  font-weight: 800;
  color: #444;
}
.history-day-title .date {
  font-size: 0.68rem;
  font-weight: 600;
  color: #aaa;
  unicode-bidi: plaintext;
}
.history-card {
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.history-card.good {
  background: #e8f5e9;
  border-color: #a5d6a7;
}
.history-card.bad {
  background: #ffebee;
  border-color: #ef9a9a;
}
.history-card.neutral {
  background: #f5f5f5;
  border-color: #e0e0e0;
}
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.history-worker {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 800;
  color: #222;
}
.history-avatar {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: rgba(21,101,192,0.12);
  color: #1565c0;
  font-weight: 800;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.history-shift {
  font-size: 0.7rem;
  font-weight: 700;
  color: #1565c0;
  background: rgba(255,255,255,0.65);
  border-radius: 999px;
  padding: 2px 8px;
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}
.history-metrics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px 12px;
}
.history-metric {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: 0.78rem;
}
.history-metric.result {
  margin-inline-start: auto;
  background: rgba(255,255,255,0.55);
  border-radius: 8px;
  padding: 2px 8px;
}
.history-label {
  font-size: 0.66rem;
  color: rgba(0,0,0,0.45);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
}
.history-value {
  font-weight: 700;
  font-size: 0.8rem;
  font-family: 'Courier New', monospace;
  color: #333;
  unicode-bidi: plaintext;
}
.history-metric.result .history-value {
  font-size: 0.9rem;
  font-weight: 800;
}
.history-value.good {
  color: #2e7d32;
}
.history-value.bad {
  color: #c62828;
}
.history-value.neutral {
  color: #666;
}
.history-empty {
  text-align: center;
  color: #888;
  padding: 20px 0;
  font-size: 0.95rem;
}
@media (max-width: 380px) {
  .history-metric { font-size: 0.72rem; }
  .history-value { font-size: 0.76rem; }
  .history-metric.result .history-value { font-size: 0.84rem; }
}
