:root {
  --mac-bg: #e8e8ea;
  --mac-window-bg: #ececec;
  --mac-sidebar-bg: #e4e3e8;
  --mac-content-bg: #ffffff;
  --mac-titlebar-bg: #ececec;
  --mac-border: #d1d1d3;
  --mac-text: #1d1d1f;
  --mac-secondary-text: #6e6e73;
  --mac-blue: #0071e3;
  --mac-red: #ff3b30;
  --mac-row-hover: #f0f6ff;
  --mac-row-selected: #0071e3;
  --mac-shadow: 0 20px 60px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --mac-bg: #1e1e1e;
    --mac-window-bg: #2b2b2d;
    --mac-sidebar-bg: #252527;
    --mac-content-bg: #1e1e1f;
    --mac-titlebar-bg: #2b2b2d;
    --mac-border: #3a3a3c;
    --mac-text: #f5f5f7;
    --mac-secondary-text: #98989d;
    --mac-row-hover: #2c3a4d;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--mac-bg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--mac-text);
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.mac-window {
  width: 100%;
  max-width: 1100px;
  height: 82vh;
  min-height: 500px;
  background: var(--mac-window-bg);
  border-radius: 12px;
  box-shadow: var(--mac-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--mac-border);
}

.mac-titlebar {
  height: 38px;
  background: var(--mac-titlebar-bg);
  border-bottom: 1px solid var(--mac-border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  position: relative;
  flex: none;
}

.traffic-lights {
  display: flex;
  gap: 8px;
}

.traffic-lights .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot.red { background: #ff5f57; }
.dot.yellow { background: #febc2e; }
.dot.green { background: #28c840; }

.mac-title {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--mac-secondary-text);
  pointer-events: none;
}

.mac-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* Sidebar */
.mac-sidebar {
  width: 210px;
  background: var(--mac-sidebar-bg);
  border-right: 1px solid var(--mac-border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: none;
}

.sidebar-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--mac-secondary-text);
  text-transform: uppercase;
  padding: 4px 10px 6px;
  letter-spacing: 0.4px;
}

.sidebar-item {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 2px;
  color: var(--mac-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sidebar-item:active {
  transform: scale(0.98);
  opacity: 0.85;
}

.sidebar-item.active {
  background: var(--mac-blue);
  color: #fff;
}

/* Summary panel */
.mac-summary {
  margin: 14px 4px 0;
  padding: 12px 10px;
  background: var(--mac-content-bg);
  border: 1px solid var(--mac-border);
  border-radius: 8px;
}

.mac-summary-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--mac-secondary-text);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.mac-summary-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 3px;
  color: var(--mac-text);
}

.mac-summary-target {
  font-size: 13px;
  font-weight: 500;
  color: var(--mac-secondary-text);
}

.mac-summary-track {
  height: 5px;
  border-radius: 3px;
  background: var(--mac-border);
  margin-top: 8px;
  overflow: hidden;
}

.mac-summary-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--mac-blue);
  width: 0%;
  transition: width 0.4s ease;
}

.mac-summary-fill.complete {
  background: #28c840;
}

.mac-summary-sub {
  font-size: 11px;
  color: var(--mac-secondary-text);
  margin-top: 6px;
  line-height: 1.4;
}

.mac-summary-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: none;
  background: none;
  padding: 8px 0 0;
  margin-top: 8px;
  border-top: 1px solid var(--mac-border);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--mac-blue);
  cursor: pointer;
  font-family: inherit;
}

.mac-summary-toggle .chev {
  transition: transform 0.2s ease;
}

.mac-summary-toggle.open .chev {
  transform: rotate(180deg);
}

.mac-summary-history {
  padding-top: 4px;
}

.mac-summary-history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 0;
  font-size: 11.5px;
}

.mac-summary-history-year {
  font-weight: 700;
  color: var(--mac-text);
  flex: none;
}

.mac-summary-history-points {
  flex: 1;
  color: var(--mac-secondary-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mac-summary-history-empty {
  font-size: 11px;
  color: var(--mac-secondary-text);
  padding: 4px 0 2px;
}

.mac-print-link {
  display: block;
  text-align: center;
  margin-top: 10px;
  padding: 7px;
  border-radius: 6px;
  background: var(--mac-content-bg);
  border: 1px solid var(--mac-border);
  color: var(--mac-text);
  font-size: 12px;
  text-decoration: none;
}

.mac-history-print {
  flex: none;
  text-decoration: none;
  font-size: 12px;
  line-height: 1;
}

.mac-badge-status-hit {
  background: rgba(40, 200, 64, 0.15);
  color: #1f9c37;
}

@media (prefers-color-scheme: dark) {
  .mac-badge-status-hit {
    color: #30d158;
  }
}

.mac-badge-status-miss {
  background: var(--mac-bg);
  color: var(--mac-secondary-text);
}

/* Main */
.mac-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--mac-content-bg);
}

.mac-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--mac-border);
  flex: none;
}

.mac-search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--mac-bg);
  border: 1px solid var(--mac-border);
  border-radius: 7px;
  padding: 5px 10px;
  width: 260px;
}

.mac-search svg {
  opacity: 0.5;
  flex: none;
}

.mac-search input {
  border: none;
  background: none;
  outline: none;
  font-size: 13px;
  width: 100%;
  color: var(--mac-text);
}

.mac-btn-primary {
  background: var(--mac-blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.mac-btn-primary:hover {
  filter: brightness(1.08);
}

.mac-btn-primary:active,
.mac-btn:active,
.mac-btn-danger:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.mac-btn {
  background: var(--mac-content-bg);
  color: var(--mac-text);
  border: 1px solid var(--mac-border);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}

.mac-btn-danger {
  background: none;
  color: var(--mac-red);
  border: 1px solid var(--mac-border);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}

.mac-table-wrap {
  flex: 1;
  overflow-y: auto;
}

.mac-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.mac-table thead th {
  position: sticky;
  top: 0;
  background: var(--mac-window-bg);
  text-align: left;
  font-weight: 600;
  color: var(--mac-secondary-text);
  padding: 7px 14px;
  border-bottom: 1px solid var(--mac-border);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.mac-table tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--mac-border);
  vertical-align: middle;
  color: var(--mac-text);
}

.mac-table tbody tr {
  cursor: pointer;
}

.mac-table tbody tr:hover {
  background: var(--mac-row-hover);
}

.mac-table tbody tr:active {
  background: var(--mac-row-hover);
  filter: brightness(0.97);
}

.mac-col-tajuk {
  font-weight: 500;
}

.mac-col-secondary {
  color: var(--mac-secondary-text);
}

.mac-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  line-height: 1.5;
}

.mac-badge-cat-a {
  background: rgba(0, 113, 227, 0.12);
  color: var(--mac-blue);
}

.mac-badge-cat-b {
  background: rgba(40, 200, 64, 0.15);
  color: #1f9c37;
}

@media (prefers-color-scheme: dark) {
  .mac-badge-cat-b {
    color: #30d158;
  }
}

.mac-badge-points {
  background: rgba(255, 149, 0, 0.15);
  color: #ff9500;
}

.mac-link {
  color: var(--mac-blue);
  text-decoration: none;
}

.mac-empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--mac-secondary-text);
  font-size: 13px;
}

.mac-empty svg {
  opacity: 0.35;
  display: block;
  margin: 0 auto 10px;
}

/* Modal */
.mac-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.mac-modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.mac-modal {
  width: 420px;
  max-width: 92vw;
  background: var(--mac-window-bg);
  border-radius: 10px;
  box-shadow: var(--mac-shadow);
  border: 1px solid var(--mac-border);
  transform: scale(0.96) translateY(6px);
  transition: transform 0.18s ease;
  overflow: hidden;
}

.mac-modal-overlay.open .mac-modal {
  transform: scale(1) translateY(0);
}

.mac-modal-header {
  padding: 14px 18px 8px;
}

.mac-modal-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.mac-form {
  padding: 6px 18px 4px;
  max-height: 55vh;
  overflow-y: auto;
}

.mac-field {
  margin-bottom: 12px;
}

.mac-field label {
  display: block;
  font-size: 12px;
  color: var(--mac-secondary-text);
  margin-bottom: 4px;
}

.mac-field input,
.mac-field select {
  width: 100%;
  border: 1px solid var(--mac-border);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
  background: var(--mac-content-bg);
  color: var(--mac-text);
  outline: none;
  font-family: inherit;
}

.mac-field input[type="file"] {
  border: none;
  padding: 4px 0;
}

.cert-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
}

.cert-current a {
  color: var(--mac-blue);
  text-decoration: none;
}

.cert-current button {
  border: none;
  background: none;
  color: var(--mac-red);
  font-size: 12px;
  cursor: pointer;
}

.mac-field input:focus,
.mac-field select:focus {
  border-color: var(--mac-blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.mac-form-error {
  color: var(--mac-red);
  font-size: 12px;
  margin-bottom: 8px;
  display: none;
}

.mac-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--mac-border);
}

.mac-modal-footer-right {
  display: flex;
  gap: 8px;
}

/* Alert */
.mac-alert-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.mac-alert-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.mac-alert {
  width: 300px;
  background: var(--mac-window-bg);
  border-radius: 10px;
  border: 1px solid var(--mac-border);
  box-shadow: var(--mac-shadow);
  padding: 18px;
  text-align: center;
  transform: scale(0.96);
  transition: transform 0.15s ease;
}

.mac-alert-overlay.open .mac-alert {
  transform: scale(1);
}

.mac-alert p {
  margin: 0 0 16px;
  font-size: 13px;
}

.mac-alert-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}
