:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #dbeafe;
  --success: #15803d;
  --success-bg: #dcfce7;
  --success-border: #86efac;
  --amber-bg: #fef3c7;
  --amber-border: #fcd34d;
  --amber-text: #92400e;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

button, input, select {
  font-family: inherit;
  font-size: 15px;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: 96px;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.15);
}

.topbar-brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar-title {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sub {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.role-pill {
  background: rgba(255, 255, 255, 0.22);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Container */
.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Cards & Controls */
.card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 10px 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-ghost-white {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
}

.btn-outline-primary {
  border-color: var(--primary);
  color: var(--primary);
  background: #eff6ff;
}

.btn-outline-danger {
  border-color: #fca5a5;
  color: var(--danger);
  background: #fef2f2;
}

.input, .select {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}

.input:focus, .select:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.row-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Week Toolbar */
.week-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.week-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.week-label {
  font-weight: 700;
  font-size: 15px;
  color: var(--primary);
}

.action-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  align-items: center;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: inline-block;
}

.swatch-normal { background: var(--success-bg); border-color: var(--success-border); }
.swatch-carry { background: var(--amber-bg); border-color: var(--amber-border); }
.swatch-draft { background: #fff; border: 2px dashed #4f46e5; }

/* Worker Card-Table Hybrid */
.worker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.worker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-light);
}

.worker-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.worker-name {
  font-weight: 700;
  font-size: 15px;
}

.worker-code {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  background: #e2e8f0;
  color: #334155;
}

.worker-code.missing {
  background: #fef2f2;
  color: #b91c1c;
}

.worker-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.total-pill {
  background: var(--primary);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
}

.icon-btn {
  min-width: 34px;
  min-height: 34px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.icon-btn.danger {
  color: var(--danger);
  border-color: #fecaca;
}

/* Grid Table */
.grid-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  user-select: none;
  -webkit-user-select: none;
}

.grid-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 560px;
}

.grid-table th,
.grid-table td {
  border: 1px solid var(--border-light);
  text-align: center;
  padding: 0;
}

.grid-table thead th {
  background: #f8fafc;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 4px;
  color: #334155;
}

.grid-table thead th.extra-day {
  background: #eff6ff;
  color: var(--primary);
}

.day-sub {
  display: block;
  font-weight: 500;
  font-size: 11px;
  color: var(--text-muted);
}

.sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 76px;
  background: #f8fafc;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  padding: 6px 6px !important;
  border-right: 2px solid var(--border) !important;
}

.plus-day-th {
  width: 54px;
  background: #f0fdf4 !important;
}

.plus-btn {
  width: 100%;
  min-height: 38px;
  border: none;
  background: transparent;
  color: var(--success);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.plus-slot-row td {
  background: #fafafa;
}

.plus-slot-btn {
  width: 100%;
  min-height: 34px;
  border: none;
  background: transparent;
  color: var(--success);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  padding-left: 10px;
}

.cell-btn {
  width: 100%;
  min-height: 46px;
  border: none;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  position: relative;
  color: var(--text);
}

.cell-btn.filled {
  background: var(--success-bg);
  color: var(--success);
}

.cell-btn.carry-over {
  background: var(--amber-bg);
  color: var(--amber-text);
}

.cell-btn.draft-changed {
  box-shadow: inset 0 0 0 2px #4f46e5;
}

.cell-btn.selected {
  background: var(--primary-soft) !important;
  color: var(--primary) !important;
  box-shadow: inset 0 0 0 2.5px var(--primary) !important;
}

.cell-check {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 10px;
  font-weight: 800;
  color: var(--primary);
}

/* Bottom Selection Bar */
.selection-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: #0f172a;
  color: #fff;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.25);
}

.selection-info {
  font-size: 14px;
  font-weight: 700;
}

.selection-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Login Screen */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

.login-title {
  margin: 0 0 4px 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
}

.login-sub {
  margin: 0 0 18px 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Notice & Badges */
.notice {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  border: 1px solid;
}

.notice-info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.notice-warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.notice-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.25);
}

.modal-title {
  margin: 0 0 14px 0;
  font-size: 17px;
  font-weight: 700;
}

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

/* Toast */
.toast-root {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 380px);
  pointer-events: none;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.25);
  text-align: center;
}

.toast.success { background: #15803d; }
.toast.error { background: #dc2626; }

/* List items for logs, accounts, daily */
.list-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
}

.badge-slot {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--success-bg);
  color: var(--success);
  font-size: 12px;
  font-weight: 600;
  margin-right: 4px;
  margin-top: 3px;
}
