* {
  box-sizing: border-box;
}

:root {
  --bg: #f3f5f9;
  --text: #1f2937;
  --muted: #4b5563;
  --card-bg: #ffffff;
  --card-border: #e5e7eb;
  --card-shadow: rgba(15, 23, 42, 0.04);
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --disabled-bg: #e2e8f0;
  --disabled-text: #334155;
  --btn-primary: #0f766e;
  --btn-border: #0f766e;
  --btn-secondary-bg: #ffffff;
  --btn-secondary-text: #0f766e;
  --table-border: #d1d5db;
  --table-head-bg: #f3f4f6;
  --row-open-bg: #ffffff;
  --row-closed-bg: #f8fafc;
}

body.dark {
  --bg: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --card-bg: #111827;
  --card-border: #334155;
  --card-shadow: rgba(2, 6, 23, 0.5);
  --input-bg: #0b1220;
  --input-border: #475569;
  --disabled-bg: #1f2937;
  --disabled-text: #cbd5e1;
  --btn-primary: #0f766e;
  --btn-border: #0f766e;
  --btn-secondary-bg: #0b1220;
  --btn-secondary-text: #5eead4;
  --table-border: #475569;
  --table-head-bg: #1e293b;
  --row-open-bg: #0f172a;
  --row-closed-bg: #111827;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px 14px 24px;
}

header h1 {
  margin: 0 0 6px;
}

header p {
  margin: 0 0 20px;
  color: var(--muted);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

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

.auth-user-chip {
  border: 1px solid var(--input-border);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--input-bg);
}

.header-actions button {
  padding: 6px 9px;
  font-size: 12px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px var(--card-shadow);
}

.card h2 {
  margin: 0 0 12px;
}

.header-mini-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  min-width: 320px;
  max-width: 420px;
  flex: 1;
}

.section-stat-card {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 5px 6px;
  text-align: center;
  background: var(--input-bg);
}

.section-stat-card.section-jeweler {
  border-color: #2563eb;
  background: color-mix(in srgb, #2563eb 12%, var(--input-bg));
}

.section-stat-card.section-polish {
  border-color: #d97706;
  background: color-mix(in srgb, #d97706 12%, var(--input-bg));
}

.section-stat-card.section-setting {
  border-color: #7c3aed;
  background: color-mix(in srgb, #7c3aed 12%, var(--input-bg));
}

.section-stat-card.section-grinder {
  border-color: #059669;
  background: color-mix(in srgb, #059669 12%, var(--input-bg));
}

.section-stat-name {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 2px;
  font-weight: 700;
  line-height: 1;
}

.section-stat-count {
  font-size: 16px;
  line-height: 1;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}

.section-stat-label {
  font-size: 9px;
  color: var(--muted);
}

.section-worker-mini-list {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  align-content: flex-start;
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.section-worker-mini-chip {
  font-size: 8px;
  line-height: 1.2;
  border: 1px solid var(--input-border);
  border-radius: 999px;
  padding: 1px 4px;
  color: var(--muted);
  background: var(--bg);
  white-space: nowrap;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.grid {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

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

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.grid.three {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.picker-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.picker-title {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
}

.option-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-btn {
  width: 100%;
  text-align: left;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  padding: 9px 12px;
}

.option-btn.active {
  border-color: #0f766e;
  background: #0f766e;
  color: #fff;
}

.section-btn,
.worker-btn {
  border-left-width: 4px;
}

.section-btn.section-jeweler,
.worker-btn.section-jeweler,
.section-cell.section-jeweler {
  border-left-color: #2563eb;
}

.section-btn.section-polish,
.worker-btn.section-polish,
.section-cell.section-polish {
  border-left-color: #d97706;
}

.section-btn.section-setting,
.worker-btn.section-setting,
.section-cell.section-setting {
  border-left-color: #7c3aed;
}

.section-btn.section-grinder,
.worker-btn.section-grinder,
.section-cell.section-grinder {
  border-left-color: #059669;
}

.section-btn.section-jeweler:not(.active),
.worker-btn.section-jeweler:not(.active) {
  background: color-mix(in srgb, #2563eb 10%, var(--input-bg));
}

.section-btn.section-polish:not(.active),
.worker-btn.section-polish:not(.active) {
  background: color-mix(in srgb, #d97706 10%, var(--input-bg));
}

.section-btn.section-setting:not(.active),
.worker-btn.section-setting:not(.active) {
  background: color-mix(in srgb, #7c3aed 10%, var(--input-bg));
}

.section-btn.section-grinder:not(.active),
.worker-btn.section-grinder:not(.active) {
  background: color-mix(in srgb, #059669 10%, var(--input-bg));
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}

input,
select,
button {
  font: inherit;
  border-radius: 8px;
}

input,
select {
  border: 1px solid var(--input-border);
  padding: 10px 12px;
  background: var(--input-bg);
  color: var(--text);
}

input:disabled {
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
}

button {
  border: 1px solid var(--btn-border);
  background: var(--btn-primary);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}

button.secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
}

button.danger {
  border-color: #b91c1c;
  color: #b91c1c;
}

button.close-day {
  border-color: #0ea5e9;
  color: #0ea5e9;
}

button.close-day:hover {
  background: #e0f2fe;
}

body.dark button.close-day:hover {
  background: #132c3a;
}

button.danger:hover {
  background: #fee2e2;
}

body.dark button.danger:hover {
  background: #3f1d1d;
}

button.small-btn {
  padding: 6px 10px;
  font-size: 12px;
}

button:hover {
  filter: brightness(0.96);
}

.metal-tabs-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.metal-tabs-wrap span {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.metal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.metal-tab {
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  padding: 7px 12px;
}

.metal-tab.active {
  border-color: #0f766e;
  background: #0f766e;
  color: #fff;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 4px;
}

.table-wrap {
  overflow-x: auto;
}

.daily-search-bar {
  display: grid;
  grid-template-columns: 180px 220px 90px;
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}

.daily-search-bar label {
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
}

th,
td {
  border: 1px solid var(--table-border);
  padding: 8px;
  text-align: center;
  font-size: 15px;
}

tr.row-open {
  background: var(--row-open-bg);
}

tr.row-closed {
  background: var(--row-closed-bg);
}

tr.row-attention td {
  animation: pulse-attention 1.1s ease-in-out infinite;
}

@keyframes pulse-attention {
  0% {
    background-color: color-mix(in srgb, #fde047 45%, transparent);
  }
  50% {
    background-color: color-mix(in srgb, #fde047 8%, transparent);
  }
  100% {
    background-color: color-mix(in srgb, #fde047 45%, transparent);
  }
}

tr.section-jeweler td:first-child {
  border-left: 4px solid #2563eb;
}

tr.section-polish td:first-child {
  border-left: 4px solid #d97706;
}

tr.section-setting td:first-child {
  border-left: 4px solid #7c3aed;
}

tr.section-grinder td:first-child {
  border-left: 4px solid #059669;
}

.section-cell {
  font-weight: 700;
}

th {
  background: var(--table-head-bg);
}

.inline-finish-input {
  width: 110px;
  padding: 6px 8px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  text-align: center;
  background: var(--input-bg);
  color: var(--text);
  font-size: 15px;
}

.tiny-delete-btn {
  width: 22px;
  height: 22px;
  min-width: 22px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid #dc2626;
  background: #dc2626;
  color: #fff;
  font-size: 11px;
  line-height: 1;
  font-weight: 700;
}

.tiny-delete-btn:hover {
  filter: brightness(0.9);
}

.status {
  min-height: 20px;
  margin: 0;
  color: var(--btn-primary);
  font-weight: 600;
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.report-item {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 10px;
}

.performance-counter-panel {
  margin-top: 8px;
  border-top: 1px solid var(--card-border);
  padding-top: 6px;
}

.performance-counter-panel h4 {
  margin: 0 0 6px;
  font-size: 13px;
}

#performanceCounterBody {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.performance-section {
  min-width: 140px;
  flex: 1;
}

.performance-section-title {
  margin: 6px 0 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.performance-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  margin-bottom: 0;
  border: 0;
  background: transparent;
}

.performance-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.performance-value {
  font-size: 13px;
  font-weight: 700;
  min-width: 0;
  text-align: left;
  white-space: nowrap;
}

.start-finish-cell {
  min-width: 320px;
}

.start-finish-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.start-finish-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.start-finish-weight {
  font-weight: 600;
}

.start-finish-worker {
  color: var(--muted);
  font-weight: 700;
}

.start-finish-badge {
  display: inline;
  padding: 0;
  border: 0;
  font-weight: 800;
  font-size: 12px;
  line-height: 1;
  background: transparent;
}

.start-finish-badge.section-jeweler {
  color: #2563eb;
  border-color: color-mix(in srgb, #2563eb 65%, var(--card-border));
}

.start-finish-badge.section-polish {
  color: #d97706;
  border-color: color-mix(in srgb, #d97706 65%, var(--card-border));
}

.start-finish-badge.section-setting {
  color: #7c3aed;
  border-color: color-mix(in srgb, #7c3aed 65%, var(--card-border));
}

.start-finish-badge.section-grinder {
  color: #059669;
  border-color: color-mix(in srgb, #059669 65%, var(--card-border));
}

.start-finish-separator {
  display: inline-block;
  width: 0;
  height: 1.2em;
  border-left: 2px solid #475569;
  margin: 0 8px;
  vertical-align: middle;
}

.help-card p {
  margin: 6px 0;
}

#workerReportTable {
  min-width: 420px;
}

#workerReportBody tr td:first-child {
  font-weight: 700;
}

.report-table-wrap {
  max-height: 320px;
}

.report-dustin-input {
  width: 90px;
  padding: 4px 6px;
  text-align: center;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
}

.report-difference-cell {
  font-weight: 700;
  color: var(--text);
  background: color-mix(in srgb, var(--input-bg) 85%, #334155 15%);
}

@media (max-width: 980px) {
  .header-top {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .header-mini-stats {
    grid-template-columns: 1fr;
    min-width: 0;
    max-width: none;
  }

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

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

  .daily-search-bar {
    grid-template-columns: 1fr;
  }
}

.app-footer {
  position: fixed;
  right: 10px;
  bottom: 8px;
  text-align: right;
  opacity: 0.72;
  user-select: none;
  pointer-events: none;
  z-index: 50;
}

#ownershipSignature {
  font-size: 11px;
  letter-spacing: 0.3px;
  background: color-mix(in srgb, var(--card-bg) 88%, transparent);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 2px 8px;
}
