:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef5f7;
  --text: #142026;
  --muted: #64737d;
  --border: #d9e1e6;
  --accent: #00645d;
  --accent-strong: #004a45;
  --accent-soft: #d9f1ee;
  --warning: #fff2bf;
  --shadow: 0 18px 50px rgba(15, 34, 41, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  overflow-x: hidden;
}

.topbar {
  align-items: center;
  background: linear-gradient(135deg, #003b3b, #00645d);
  color: #fff;
  display: flex;
  justify-content: space-between;
  min-height: 76px;
  padding: 16px 28px;
}

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

.back-button {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  color: #fff;
  display: none;
  font-size: 30px;
  height: 44px;
  line-height: 1;
  min-height: 44px;
  padding: 0;
  width: 44px;
}

body.admin-page .back-button,
body.detail-page .back-button {
  display: inline-flex;
}

.brand-mark {
  align-items: center;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  display: flex;
  height: 44px;
  justify-content: center;
  width: 44px;
}

.brand-mark svg {
  height: 28px;
  width: 28px;
}

.brand h1 {
  font-size: 22px;
  line-height: 1.2;
  margin: 0;
}

.brand p {
  color: rgba(255, 255, 255, 0.74);
  font-size: 13px;
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  display: none;
}

.status-pill {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  display: none;
  font-size: 13px;
  padding: 8px 12px;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}

body:not(.admin-page) .admin-only {
  display: none;
}

body:not(.admin-page) .workspace {
  grid-template-columns: minmax(0, 1fr);
}

body.detail-page .searchbar,
body.detail-page .filterbar,
body.detail-page .metrics {
  display: none;
}

.sidebar {
  background: #fbfcfd;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
}

.content {
  padding: 28px;
}

.panel,
.metrics,
.results-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel h2,
.results-header h2 {
  font-size: 17px;
  line-height: 1.25;
  margin: 0;
}

.source-card {
  align-items: center;
  display: flex;
  gap: 12px;
  margin: 16px 0;
}

.source-icon {
  align-items: center;
  background: #107c41;
  border-radius: 6px;
  color: #fff;
  display: flex;
  font-size: 12px;
  font-weight: 800;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.source-card strong,
.source-card span {
  display: block;
}

.source-card span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.button-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

button,
.button {
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 650;
  gap: 8px;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
}

button:hover,
.button:hover {
  border-color: #b9c9cf;
}

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

.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

#fileInput {
  display: none;
}

.helper-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 14px 0 0;
}

.section-title {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
}

select {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  min-height: 36px;
  padding: 8px 10px;
  width: 160px;
}

.preview-table-wrap,
.results-table-wrap {
  max-width: 100%;
  min-width: 0;
  overflow: auto;
}

.preview-table-wrap {
  border: 1px solid var(--border);
  border-radius: 7px;
  max-height: 280px;
}

.storage-list {
  display: grid;
  gap: 12px;
  margin: 16px 0 0;
}

.storage-list div {
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 4px;
  padding-bottom: 12px;
}

.storage-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.storage-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.storage-list dd {
  font-size: 14px;
  font-weight: 650;
  margin: 0;
  overflow-wrap: anywhere;
}

.searchbar {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(240px, 1fr) auto;
  margin-bottom: 14px;
}

.search-input {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  min-height: 58px;
  padding: 0 18px;
}

.search-input span {
  color: var(--accent);
  font-size: 30px;
  line-height: 1;
}

.search-input input {
  border: 0;
  color: var(--text);
  font-size: 17px;
  min-width: 0;
  outline: none;
  width: 100%;
}

.filterbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(180px, 260px) minmax(240px, 1fr);
  margin-bottom: 18px;
  padding: 14px;
}

.filterbar label {
  display: grid;
  gap: 7px;
}

.filterbar label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.filterbar input,
.filterbar select {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  min-height: 42px;
  outline: none;
  padding: 9px 11px;
  width: 100%;
}

.filterbar input:focus,
.filterbar select:focus,
.search-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 100, 93, 0.12);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 24px;
  padding: 18px;
}

.metric {
  border-right: 1px solid var(--border);
  padding: 0 22px;
}

.metric:last-child {
  border-right: 0;
}

.metric span {
  color: var(--accent);
  display: block;
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

.metric label {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-top: 8px;
}

.results-header {
  align-items: end;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.results-header p {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0 0;
}

body:not(.admin-page):not(.detail-page) #exportButton {
  display: none;
}

.data-table {
  border-collapse: collapse;
  min-width: 900px;
  width: 100%;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  padding: 14px 16px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: #f8fafb;
  color: #34444d;
  font-weight: 750;
  position: sticky;
  top: 0;
}

.data-table.compact {
  min-width: 520px;
}

.data-table.compact th,
.data-table.compact td {
  font-size: 12px;
  padding: 8px 10px;
}

.match {
  background: var(--warning);
  border-radius: 4px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  padding: 2px 4px;
}

.empty-state {
  color: var(--muted);
  padding: 48px 16px !important;
  text-align: center !important;
}

.detail-link {
  background: var(--accent);
  border-radius: 7px;
  color: #fff;
  display: inline-flex;
  font-size: 13px;
  font-weight: 750;
  min-height: 34px;
  padding: 8px 12px;
  text-decoration: none;
}

.number-cell,
.attendance-day,
.total-cell {
  text-align: center !important;
}

.employee-name-cell {
  font-weight: 750;
  min-width: 220px;
}

.attendance-day {
  min-width: 48px;
  width: 48px;
}

.weekend-cell {
  background: #ffff00 !important;
}

.total-cell {
  background: #ffff00 !important;
  font-weight: 800;
  min-width: 84px;
}

body.detail-page .data-table {
  min-width: 1800px;
}

body.detail-page .data-table th,
body.detail-page .data-table td {
  border: 1px solid #8f969b;
  padding: 8px 10px;
  white-space: nowrap;
}

body.detail-page .data-table th {
  background: #fff;
  color: #142026;
  text-align: center;
}

body.detail-page .data-table thead th {
  font-size: 16px;
}

body.detail-page .original-cell:first-child {
  text-align: center !important;
  width: 56px;
}

body.detail-page .employee-name-cell {
  min-width: 260px;
}

.detail-mobile-table {
  display: none;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 18px;
  }

  .metric:nth-child(2) {
    border-right: 0;
  }
}

@media (max-width: 640px) {
  .topbar,
  .results-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand > div:last-child {
    max-width: min(260px, calc(100vw - 96px));
    min-width: 0;
  }

  .brand {
    align-items: flex-start;
    width: 100%;
  }

  .brand p {
    white-space: normal;
  }

  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .section-title select {
    width: 100%;
  }

  .workspace,
  .content,
  .sidebar {
    min-width: 0;
  }

  .topbar {
    padding: 18px;
  }

  .content,
  .sidebar {
    padding: 18px;
    width: 100%;
  }

  .panel,
  .metrics,
  .results-table-wrap,
  .searchbar,
  .filterbar,
  .results-header {
    max-width: calc(100vw - 36px);
    width: 100%;
  }

  button,
  .button {
    min-width: 0;
  }

  .searchbar,
  .filterbar,
  .button-row {
    grid-template-columns: 1fr;
  }

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

  body:not(.admin-page):not(.detail-page) .metrics {
    display: none;
  }

  .metric {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 0 0 16px;
  }

  .metric:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  body:not(.admin-page):not(.detail-page) .results-table-wrap {
    border-radius: 8px;
    overflow-x: visible;
  }

  body:not(.admin-page):not(.detail-page) .data-table {
    border: 1px solid var(--border);
    border-collapse: separate;
    border-radius: 8px;
    border-spacing: 0;
    min-width: 0;
    overflow: hidden;
    table-layout: fixed;
  }

  body:not(.admin-page):not(.detail-page) .data-table th,
  body:not(.admin-page):not(.detail-page) .data-table td {
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    font-size: 14px;
    line-height: 1.35;
    padding: 16px 12px;
    vertical-align: middle;
  }

  body:not(.admin-page):not(.detail-page) .data-table th:last-child,
  body:not(.admin-page):not(.detail-page) .data-table td:last-child {
    border-right: 0;
  }

  body:not(.admin-page):not(.detail-page) .data-table tbody tr:last-child td {
    border-bottom: 0;
  }

  body:not(.admin-page):not(.detail-page) .data-table th:first-child,
  body:not(.admin-page):not(.detail-page) .data-table td:first-child {
    display: none;
  }

  body:not(.admin-page):not(.detail-page) .data-table th:nth-child(2),
  body:not(.admin-page):not(.detail-page) .data-table td:nth-child(2) {
    width: 47%;
  }

  body:not(.admin-page):not(.detail-page) .data-table th:nth-child(3),
  body:not(.admin-page):not(.detail-page) .data-table td:nth-child(3) {
    text-align: center;
    width: 25%;
  }

  body:not(.admin-page):not(.detail-page) .data-table th:nth-child(4),
  body:not(.admin-page):not(.detail-page) .data-table td:nth-child(4) {
    text-align: center;
    width: 28%;
  }

  body:not(.admin-page):not(.detail-page) .detail-link {
    font-size: 12px;
    justify-content: center;
    padding: 8px 10px;
    width: 100%;
  }

  body.detail-page .results-table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: auto;
    padding: 0;
  }

  body.detail-page .detail-desktop-table {
    display: none;
  }

  body.detail-page .detail-mobile-table {
    border: 0;
    border-collapse: separate;
    border-radius: 8px;
    border-spacing: 0;
    display: table;
    margin: 0;
    overflow: hidden;
    width: 100%;
  }

  body.detail-page .detail-mobile-table th,
  body.detail-page .detail-mobile-table td {
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.35;
    padding: 16px 12px;
    text-align: center;
  }

  body.detail-page .detail-mobile-table th {
    background: #f8fafb;
    color: #34444d;
    font-size: 14px;
    font-weight: 750;
  }

  body.detail-page .detail-mobile-table .weekend-row td {
    background: #ffff00;
  }

  body.detail-page .detail-mobile-table th,
  body.detail-page .detail-mobile-table td {
    border-left: 0;
    border-top: 0;
  }

  body.detail-page .detail-mobile-table th:last-child,
  body.detail-page .detail-mobile-table td:last-child {
    border-right: 0;
  }

  body.detail-page .detail-mobile-table tbody tr:last-child td {
    border-bottom: 0;
  }

  body.detail-page .detail-mobile-table td:first-child {
    width: 50%;
  }

  body.detail-page .detail-mobile-table td:last-child {
    width: 50%;
  }

  body.detail-page .detail-mobile-table .mobile-total-row td {
    color: #ff0000;
    font-weight: 800;
  }

  body.detail-page .results-header {
    margin-bottom: 16px;
  }

  body.detail-page .results-header h2 {
    font-size: 20px;
    font-weight: 750;
  }

  body.detail-page .results-header p {
    color: var(--text);
    font-size: 17px;
    font-weight: 500;
  }
}
