:root {
  --bg: #f6f3ef;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --brand: #1d4ed8;
  --accent: #f59e0b;
  --line: #e5e7eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--ui-bg, #f8fafc);
}

.layout-main .history-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0;
}

.history-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 0 22px;
}

.history-page-kicker {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

.history-page-title {
  margin: 0;
  font-size: 34px;
  line-height: 1.15;
  color: #0f172a;
}

.history-page-desc {
  margin: 10px 0 0;
  max-width: 720px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
}

.history-page-links {
  display: inline-flex;
  gap: 10px;
  flex-wrap: wrap;
}

.history-card {
  display: block !important;
}

.history-loading {
  padding: 18px 2px;
  font-size: 14px;
  color: var(--muted);
}

.appbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(6px);
}

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

.brand-badge {
  width: 12px;
  height: 12px;
  background: var(--brand);
  border-radius: 2px;
  transform: rotate(20deg);
}

.appbar-actions {
  display: flex;
  gap: 10px;
}

.container {
  max-width: 1100px;
  margin: 28px auto 64px;
  padding: 0 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}

.card-hd {
  font-weight: 700;
  margin-bottom: 12px;
}

.form {
  display: grid;
  gap: 12px;
}

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

.field {
  display: grid;
  gap: 6px;
}

.lbl {
  font-size: 14px;
  color: var(--muted);
}

input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

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

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}

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

.btn.ghost {
  background: transparent;
}

.btn.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn.btn-icon img {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.msg {
  min-height: 20px;
  font-size: 13px;
  color: #dc2626;
}

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

/* ===== History Toolbar ===== */
.history-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

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

.tab {
  border: 1px solid var(--line);
  background: #fff;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

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

.history-list {
  display: grid;
  gap: 12px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  transition: all 0.25s ease;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.02);
}

.history-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  border-color: #cbd5e1;
}

.history-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 20px 24px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
}

.history-summary-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.history-summary-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  /* Take up all remaining space */
  min-width: 0;
  /* Prevent overflow */
}

.history-summary-title {
  font-size: 16px;
  font-weight: 700;
  color: #1e293b;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-summary-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
}

.history-summary-meta span {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.history-summary-right {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
}

.history-hours {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.history-hours-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--brand, #3b82f6);
  line-height: 1;
}

.history-hours-lbl {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  margin-top: 4px;
}

.history-chevron {
  color: #94a3b8;
  transition: transform 0.2s ease, color 0.2s ease;
  display: flex;
}

.history-item:hover .history-chevron {
  transform: translateX(4px);
  color: var(--brand, #3b82f6);
}

@media (max-width: 768px) {
  .history-page-head {
    flex-direction: column;
    padding-bottom: 18px;
  }

  .history-page-title {
    font-size: 28px;
  }

  .history-page-links {
    width: 100%;
  }

  .history-summary {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
  }

  .history-summary-right {
    justify-content: space-between;
    width: 100%;
    flex-direction: row-reverse;
  }
}

.history-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #e2e8f0;
  color: #1f2937;
}

.history-badge.in {
  background: #dbeafe;
  color: #1d4ed8;
}

.history-badge.out {
  background: #fef3c7;
  color: #b45309;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #e5e7eb;
  color: #374151;
}

.status-badge.pending {
  background: #fef3c7;
  color: #92400e;
}

.status-badge.approved {
  background: #dcfce7;
  color: #166534;
}

.status-badge.rejected {
  background: #fee2e2;
  color: #991b1b;
}

.history-summary:hover {
  background: #f8fafc;
}

.history-detail {
  padding: 14px 16px 18px;
  border-top: 1px solid var(--line);
  background: #fbfbfb;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}

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

textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  min-height: 90px;
  resize: vertical;
}

.attachment-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.attachment-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  background: #fff;
  font-size: 12px;
}

@media (max-width: 900px) {
  .history-summary {
    grid-template-columns: 1fr;
    gap: 6px;
  }

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

.history-detail {
  border-top: 1px dashed var(--line);
  padding: 16px;
  display: grid;
  gap: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-grid .field textarea {
  min-height: 100px;
}

.detail-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.attachment-links {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.attachment-link {
  color: var(--brand);
  text-decoration: underline;
  font-size: 13px;
}



@media (max-width: 900px) {
  .history-summary {
    grid-template-columns: 1fr;
  }

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


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

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.dot.pass {
  background: #22c55e;
}

.dot.fail {
  background: #ef4444;
}

.history-list-wrap {
  margin-top: 18px;
}

.history-list-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.history-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}

.history-info {
  display: grid;
  gap: 4px;
}

.history-title {
  font-weight: 600;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 12px;
}

.badge {
  min-width: 52px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
}

.badge.pass {
  background: #dcfce7;
  color: #166534;
}

.badge.fail {
  background: #fee2e2;
  color: #991b1b;
}

@media (max-width: 760px) {
  .grid.g-2 {
    grid-template-columns: 1fr;
  }

  .history-summary {
    grid-template-columns: 1fr;
  }

  .appbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}


/* ==== History polish overrides ==== */
.history-list {
  gap: 14px;
}

.history-item {
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.history-summary {
  grid-template-columns: 110px 90px 1fr 160px 180px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfc 100%);
}

.history-detail {
  background: #fcfcfd;
  border-top: 1px solid var(--line);
}

.detail-form {
  display: grid;
  gap: 14px;
}

.detail-grid {
  gap: 14px 18px;
}

.detail-grid .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: transparent;
  border: 0;
  padding: 0;
}

.detail-grid .field .lbl {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
}

.detail-grid input,
.detail-grid textarea,
.detail-grid select {
  width: 100%;
  border: 1px solid #d6dae6;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.detail-grid textarea {
  min-height: 96px;
  resize: vertical;
}

.detail-actions {
  justify-content: flex-end;
}

@media (max-width: 900px) {
  .history-summary {
    grid-template-columns: 1fr;
    gap: 6px;
  }

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


/* ==== Force detail below summary ==== */
.history-item {
  display: block;
  padding: 0;
}

.history-item>.history-summary {
  width: 100%;
}

.history-item>.history-detail {
  width: 100%;
}


/* PDF preview in history detail */
.pdf-preview-wrap {
  margin-top: 10px;
  background: #ffffff;
  border: 1px solid #eef0f4;
  border-radius: 12px;
  padding: 12px;
}

.pdf-preview {
  border: 1px dashed #e5e7eb;
  border-radius: 10px;
  padding: 8px 10px;
}

.pdf-preview>summary {
  cursor: pointer;
  font-weight: 600;
}

.pdf-list {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.pdf-item {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 6px 8px;
  background: #fafafa;
}

.pdf-item>summary {
  cursor: pointer;
  font-size: 13px;
}

.pdf-frame {
  margin-top: 8px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  background: #fff;
}

.pdf-frame iframe {
  width: 100%;
  height: 360px;
  border: 0;
}


.pdf-open {
  display: inline-flex;
  margin-top: 6px;
  font-size: 12px;
  color: #2563eb;
  text-decoration: underline;
}


.pdf-empty {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 13px;
  border: 1px solid #fed7aa;
}

/* ==== Align detail form with teacher/teacher_in styles ==== */
.history-detail {
  padding: 20px;
  background: #ffffff;
  border-top: 1px solid var(--line);
  display: block;
}

.detail-form {
  display: grid;
  gap: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.detail-grid .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-grid .field .lbl {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
}

.detail-grid input,
.detail-grid textarea,
.detail-grid select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #d6dae6;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.detail-grid textarea {
  min-height: 96px;
  resize: vertical;
}

.detail-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

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

/* ==== Time Slots Grid ==== */
.time-slot-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, .85fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.time-slot-row:last-child {
  margin-bottom: 0;
}

.time-slot-date-group,
.time-slot-time-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.time-slot-sep {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.time-slot-add {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
}

.btn.slot-remove {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 10px;
  color: #475569;
}

@media (max-width:840px) {
  .time-slot-row {
    grid-template-columns: 1fr;
  }

  .time-slot-date-group,
  .time-slot-time-group {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .time-slot-row .slot-remove {
    justify-self: end;
  }

  .time-slot-add {
    justify-self: end;
  }
}
