* {
  box-sizing: border-box;
}

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #182230;
  --muted: #7b8795;
  --border: #e8ecf1;
  --primary: #176b55;
  --radius: 12px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "DM Sans", sans-serif;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  padding-bottom: 32px;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sync {
  color: var(--muted);
  font-size: 12px;
}

.btn {
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
}

.btn:hover {
  border-color: #cfd6de;
}

.btn:disabled {
  opacity: .5;
  cursor: wait;
}

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

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.stat {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
}

.stat:hover {
  border-color: #cfd6de;
}

.stat.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

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

.stat strong {
  font-size: 26px;
  line-height: 1.2;
}

.stat small {
  color: var(--muted);
  font-size: 12px;
}

.is-process {
  color: #c2570c;
}

.is-done {
  color: #16a34a;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 12px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 0;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 9px;
  background: var(--bg);
}

.tab {
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .1);
}

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

.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 170px;
  padding: 16px;
}

.chart-status {
  height: auto;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 12px 16px 16px;
}

.hbar {
  display: grid;
  grid-template-columns: minmax(80px, 150px) 1fr 36px;
  align-items: center;
  gap: 10px;
  padding: 5px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.hbar:hover,
.hbar.is-active {
  background: var(--bg);
}

.hbar-label {
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hbar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}

.hbar.is-active .hbar-track,
.hbar:hover .hbar-track {
  background: #e8ecf1;
}

.hbar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.hbar-count {
  text-align: right;
  font-size: 12px;
  font-weight: 700;
}

.fill-register { background: #9ca3af; }
.fill-analisa { background: #f97316; }
.fill-koreksi { background: #eab308; }
.fill-ulangan { background: #84cc16; }
.fill-selesai { background: #16a34a; }
.fill-default { background: #64748b; }

.chart-empty {
  width: 100%;
  align-self: center;
  text-align: center;
  color: var(--muted);
}

.bar {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.bar-value {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.bar-fill {
  width: 100%;
  max-width: 32px;
  min-height: 3px;
  border-radius: 5px 5px 2px 2px;
  background: var(--primary);
}

.bar-fill.is-zero {
  background: var(--border);
}

.bar-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.1;
}

.bar-label small {
  font-size: 9px;
  opacity: .7;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 170px 130px auto;
  gap: 8px;
  margin-bottom: 12px;
}

.search-box input,
.toolbar select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  outline: none;
}

.search-box input:focus,
.toolbar select:focus,
#npkInput:focus {
  border-color: var(--primary);
}

.table-card {
  overflow: hidden;
  scroll-margin-top: 12px;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.reset {
  height: 24px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  padding: 8px 12px;
  text-align: left;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  white-space: nowrap;
}

.type-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-row {
  cursor: pointer;
}

.data-row:hover {
  background: #fafbfc;
}

.data-row.is-done {
  opacity: .72;
}

.spa-cell {
  font-weight: 600;
}

.date-cell {
  color: var(--muted);
  white-space: nowrap;
}

.table-message {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  color: var(--muted);
  font-size: 12px;
}

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

.pagination button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.pagination button:disabled {
  opacity: .4;
  cursor: default;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.status-register { background: #f1f3f5; color: #5b6572; }
.status-analisa { background: #fff1e6; color: #c2570c; }
.status-koreksi { background: #fef9c3; color: #854d0e; }
.status-ulangan { background: #ecfccb; color: #3f6212; }
.status-selesai { background: #dcfce7; color: #166534; }
.status-default { background: #f1f5f9; color: #475569; }

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(16, 24, 40, .4);
}

.modal-layer.is-open {
  display: grid;
}

.modal {
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px;
  border-radius: 14px;
  background: var(--surface);
}

.modal-small {
  width: min(360px, 100%);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 20px;
  color: var(--muted);
}

.detail-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.detail-item:last-child {
  border-bottom: 0;
}

.detail-label {
  color: var(--muted);
}

.detail-value {
  text-align: right;
  font-weight: 500;
  overflow-wrap: anywhere;
}

#npkInput {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}

.form-message {
  min-height: 18px;
  margin: 8px 0;
  color: #dc2626;
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: .2s;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 640px) {
  .app {
    width: calc(100% - 24px);
  }

  .sync {
    display: none;
  }

  .summary {
    gap: 8px;
  }

  .stat {
    padding: 12px;
  }

  .stat strong {
    font-size: 22px;
  }

  .toolbar {
    grid-template-columns: 1fr 1fr auto;
  }

  .search-box {
    grid-column: 1 / -1;
  }

  .chart {
    gap: 3px;
    padding: 12px;
  }

  th, td {
    padding: 6px 10px;
  }

  .tab {
    padding: 0 8px;
  }

  .hbar {
    grid-template-columns: minmax(70px, 110px) 1fr 30px;
    gap: 8px;
  }
}
