:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #d8dee6;
  --text: #172033;
  --muted: #667085;
  --blue: #20a0b0;
  --blue-dark: #168592;
  --soft: #eef2f6;
  --danger: #dc2626;
  --work-area-height: 360px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Malgun Gothic", "Segoe UI", sans-serif;
  font-size: 14px;
  overflow-x: hidden;
}

body.login-mode {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #ffffff;
}

button,
input,
select {
  font-family: inherit;
  font-size: 14px;
  max-width: 100%;
}

input,
select {
  border: 1px solid #cbd5df;
  border-radius: 6px;
  background: #ffffff;
  padding: 8px 9px;
  color: var(--text);
  min-width: 0;
  width: 100%;
}

button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #ffffff;
  border-radius: 6px;
  padding: 8px 11px;
  cursor: pointer;
  white-space: nowrap;
  min-width: 0;
}

button:hover {
  background: var(--blue-dark);
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

[hidden],
.hidden {
  display: none !important;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  margin-bottom: 10px;
}

p {
  color: var(--muted);
  margin-top: 4px;
}

.login-screen {
  width: 360px;
  min-height: 360px;
  display: grid;
  place-items: center;
  padding: 0;
}

.login-panel {
  width: min(320px, calc(100vw - 32px));
  min-height: 320px;
  max-height: 360px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 14px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.login-brand img {
  width: 118px;
  height: 142px;
  object-fit: contain;
  display: block;
}

.login-brand strong {
  font-size: 29px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  color: #162033;
}

.login-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.login-grid input,
.login-grid button {
  width: 100%;
  height: 38px;
}

.install-prompt {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
  padding: 10px;
  border: 1px solid #d8dee6;
  border-radius: 8px;
  background: #f7f9fc;
}

.install-prompt strong {
  display: block;
  color: var(--text);
  font-size: 13px;
}

.install-prompt p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.install-prompt button {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.form-error,
.inline-message {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 14px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 2px 8px;
  margin-bottom: 4px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-brand > div,
.panel-header > div {
  min-width: 0;
}

.topbar-logo {
  width: 36px;
  height: 44px;
  object-fit: contain;
  display: block;
  flex: 0 0 auto;
}

.topbar-brand p,
.user-badge,
.timecode span,
.metric-row span,
dt,
.active-worker span,
.active-worker small,
.empty-block {
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  min-width: 0;
}

.user-badge {
  font-weight: 700;
}

.plain-button,
.secondary-button,
.mini-button {
  background: var(--soft);
  border-color: #cbd5df;
  color: var(--text);
}

.plain-button:hover,
.secondary-button:hover,
.mini-button:hover {
  background: #f7f9fc;
}

.danger {
  background: var(--danger);
  border-color: #b91c1c;
  color: #ffffff;
}

.danger:hover {
  background: #b91c1c;
}

.tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  margin: 10px 0 0;
  padding: 0;
  background: transparent;
  border-bottom: 0;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: thin;
  position: relative;
  z-index: 2;
}

.tabs::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--border);
  z-index: 0;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: 0;
  color: #475467;
  border-radius: 7px 7px 0 0;
  padding: 10px 20px;
  font-weight: 700;
  position: relative;
  margin-bottom: 0;
  flex: 0 0 auto;
  z-index: 1;
}

.tab.active {
  background: var(--panel);
  border-color: var(--border);
  color: var(--blue);
  box-shadow: none;
  top: 1px;
  z-index: 3;
}

.tab.active::after {
  content: "";
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: -1px;
  height: 2px;
  background: var(--panel);
}

.tab:hover {
  background: #f7f9fc;
  color: var(--text);
}

.tab.active:hover {
  background: var(--panel);
  color: var(--blue);
}

.tab-panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  padding: 10px;
  margin-bottom: 10px;
  min-width: 0;
  overflow: hidden;
}

.tab-panel.active {
  display: block;
}

.panel-header,
.metric-row,
.row-actions,
.report-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header {
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  min-width: 0;
}

.panel-header h2 {
  margin-bottom: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

.status-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 10px;
  margin-bottom: 10px;
}

.status-card,
.summary-card,
.active-workers-card,
.admin-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  min-width: 0;
}

.status-grid .status-card,
.status-grid .summary-card {
  margin-bottom: 0;
}

.status-card h1 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 34px;
  line-height: 1.05;
}

.timecode {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfe;
}

.timecode strong {
  color: var(--text);
  font-size: 20px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.metric-row {
  margin: 8px 0;
}

.metric-row div,
.summary-total {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
}

.metric-row strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 16px;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-button {
  min-width: 92px;
}

.summary-total {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.summary-total span {
  color: var(--muted);
  font-size: 12px;
}

.summary-total strong {
  color: var(--text);
  font-size: 20px;
}

dl {
  display: grid;
  gap: 6px;
  margin: 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e1e7ef;
}

dd {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

.active-workers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
}

.active-worker,
.empty-block {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid #e1e7ef;
  border-radius: 6px;
  background: #fbfcfe;
}

.active-worker strong {
  color: var(--text);
  font-size: 14px;
}

.month-input {
  width: 158px;
  height: 36px;
  flex: 0 0 auto;
}

.report-employee-select {
  width: 190px;
  height: 36px;
  flex: 0 1 190px;
}

.table-wrap {
  overflow: auto;
  max-height: var(--work-area-height);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  scrollbar-width: thin;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 720px;
  background: #ffffff;
}

#reportBody {
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid #e1e7ef;
  border-right: 1px solid #e1e7ef;
  padding: 6px;
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

th {
  background: #eef2f6;
  font-weight: 700;
  position: sticky;
  top: 0;
}

.footer-total {
  margin-top: 10px;
  text-align: right;
  color: var(--muted);
  font-weight: 700;
}

.footer-total strong {
  color: var(--text);
  font-size: 18px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.admin-card-wide {
  grid-column: 1 / -1;
}

.header-action-button {
  width: auto;
  min-width: 86px;
  height: 36px;
  padding: 8px 11px;
  flex: 0 0 auto;
  align-self: flex-start;
}

.employee-form {
  display: grid;
  grid-template-columns: minmax(120px, 1.1fr) minmax(92px, 0.8fr) minmax(112px, 1fr) minmax(112px, 1fr) minmax(96px, 0.8fr) minmax(98px, 0.7fr);
  gap: 8px;
  margin-bottom: 10px;
  min-width: 0;
}

.employee-form label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.employee-form span {
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

.record-form {
  display: grid;
  grid-template-columns: minmax(124px, 0.9fr) repeat(4, minmax(104px, 1fr)) minmax(104px, 0.8fr);
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
  min-width: 0;
}

.new-record-form {
  padding: 10px;
  border: 1px solid #e1e7ef;
  border-radius: 6px;
  background: #fbfcfe;
}

.record-form button,
.employee-form button {
  min-width: 0;
  width: 100%;
  padding-left: 8px;
  padding-right: 8px;
}

.employee-form button {
  width: auto;
}

#recordEmployee,
#workerId,
#employeeId {
  min-width: 0;
}

.record-form label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.record-form span {
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

.row-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  min-width: 0;
}

.mini-button {
  min-height: 30px;
  padding: 6px 9px;
  font-size: 12px;
}

.empty-cell {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.editable-cell {
  cursor: text;
}

.editable-cell:hover {
  background: #f7fbfc;
  color: var(--blue);
}

.editing-cell {
  padding: 2px;
  background: #ffffff;
}

.editing-cell input {
  width: 100%;
  min-width: 104px;
  height: 30px;
  padding: 4px 6px;
  font-size: 12px;
}

.workers table {
  min-width: 620px;
}

.admin-card-wide .table-wrap table {
  min-width: 1420px;
}

#recordBody {
  font-size: 12px;
}

@media (max-width: 1100px) {
  .employee-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 900px) {
  .app-shell {
    padding: 14px;
  }

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

  .record-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-row,
  .report-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .month-input,
  .report-employee-select,
  .action-button {
    width: 100%;
    flex-basis: auto;
  }

  .panel-header {
    gap: 10px;
  }
}

@media (max-width: 640px) {
  :root {
    --work-area-height: 300px;
  }

  body {
    font-size: 13px;
  }

  button,
  input,
  select {
    font-size: 13px;
  }

  .app-shell {
    padding: 10px;
  }

  .topbar {
    padding-bottom: 6px;
  }

  .topbar-logo {
    width: 31px;
    height: 38px;
  }

  h1 {
    font-size: 19px;
  }

  h2 {
    font-size: 15px;
  }

  .tab {
    padding: 9px 14px;
  }

  .tab-panel {
    padding: 8px;
  }

  .status-card,
  .summary-card,
  .active-workers-card,
  .admin-card {
    padding: 10px;
  }

  .status-card h1 {
    font-size: 26px;
  }

  .timecode strong {
    font-size: 17px;
  }

  .metric-row div,
  .summary-total {
    padding: 7px 8px;
  }

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

  .employee-form button,
  .record-form button {
    min-height: 36px;
  }

  th,
  td {
    padding: 5px 6px;
    font-size: 12px;
  }

  .mini-button {
    min-height: 28px;
    padding: 5px 7px;
  }

  .install-prompt {
    display: grid;
  }
}

@media (max-width: 430px) {
  .app-shell {
    padding: 8px;
  }

  .top-actions {
    align-items: stretch;
    width: 100%;
  }

  .plain-button {
    width: 100%;
  }

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

  .tabs {
    flex-wrap: nowrap;
  }

  .install-prompt {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .install-prompt button {
    width: 100%;
  }
}
