/* Ujian Automata — shared styles */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
  background: #f5f7fb;
  color: #1f2937;
  min-height: 100vh;
  line-height: 1.5;
}
a { color: #2563eb; text-decoration: none; }
button {
  background: #2563eb;
  color: white;
  border: 0;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}
button:hover { background: #1d4ed8; }
button:disabled { background: #9ca3af; cursor: not-allowed; }
button.secondary { background: #6b7280; }
button.secondary:hover { background: #4b5563; }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; }
button.success { background: #16a34a; }
button.success:hover { background: #15803d; }
input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, textarea:focus { outline: 2px solid #2563eb; border-color: transparent; }
label { display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 4px; }
.field { margin-bottom: 14px; }

/* Login layout */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-card {
  background: white; border-radius: 12px; padding: 36px 32px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
  width: 100%; max-width: 420px;
}
.login-card h1 { font-size: 24px; margin-bottom: 6px; }
.login-card p.sub { color: #6b7280; margin-bottom: 24px; font-size: 14px; }
.login-card button { width: 100%; padding: 12px; font-size: 15px; }
.error-msg { color: #dc2626; font-size: 13px; margin-top: 10px; min-height: 18px; }

/* Top bar */
.topbar {
  background: white; border-bottom: 1px solid #e5e7eb;
  padding: 12px 24px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand { font-weight: 700; font-size: 16px; }
.topbar .info { font-size: 13px; color: #6b7280; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; padding: 6px 12px; background: #fef3c7; border-radius: 6px; color: #92400e; }
.timer.danger { background: #fee2e2; color: #991b1b; }
.warn-counter { padding: 6px 12px; background: #f3f4f6; border-radius: 6px; font-weight: 600; font-size: 13px; }
.warn-counter.lvl1 { background: #fef3c7; color: #92400e; }
.warn-counter.lvl2 { background: #fed7aa; color: #9a3412; }
.warn-counter.lvl3 { background: #fee2e2; color: #991b1b; }

/* Container */
.container { max-width: 900px; margin: 0 auto; padding: 24px; }
.container.wide { max-width: 1200px; }

.card {
  background: white; border-radius: 10px; padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06); margin-bottom: 16px;
}
.card h2 { font-size: 18px; margin-bottom: 12px; }

/* Exam questions */
.q-item {
  border-left: 4px solid #2563eb;
  padding: 16px 20px;
  margin-bottom: 14px;
  background: #f9fafb;
  border-radius: 0 8px 8px 0;
}
.q-num { font-weight: 700; color: #2563eb; font-size: 14px; margin-bottom: 8px; }
.q-points { font-size: 12px; color: #6b7280; float: right; }

/* Rich content (HTML in instructions and question text) */
.rich-content { font-size: 15px; line-height: 1.65; color: #1f2937; }
.rich-content p { margin: 8px 0; }
.rich-content strong { color: #0f172a; font-weight: 700; }
.rich-content em { font-style: italic; color: #6b21a8; }
.rich-content code, .rich-content .sym {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: #eff6ff;
  color: #1e40af;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.92em;
}
.rich-content .warn { color: #dc2626; font-weight: 700; }
.rich-content .ok { color: #059669; font-weight: 700; }
.rich-content .accent { color: #7c3aed; font-weight: 600; }
.rich-content ol, .rich-content ul { margin: 8px 0 8px 28px; }
.rich-content li { margin-bottom: 5px; }
.rich-content h3 { font-size: 16px; margin: 16px 0 8px; color: #111827; font-weight: 700; }
.rich-content h4 { font-size: 14px; margin: 12px 0 6px; color: #1f2937; font-weight: 600; }
.rich-content sup, .rich-content sub { font-size: 0.75em; }

/* Transition table */
.transition-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  margin: 14px 0 18px;
  font-size: 14px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.transition-table th {
  background: #f9fafb;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: #6b7280;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}
.transition-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
}
.transition-table tr:last-child td { border-bottom: 0; }
.transition-table td:nth-child(1),
.transition-table td:nth-child(2) {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13.5px;
  color: #1f2937;
}
.transition-table tr:nth-child(even) td { background: #fafbfc; }
.transition-table .phase-start  { color: #6b7280; font-weight: 600; font-size: 12.5px; }
.transition-table .phase-push   { color: #475569; font-size: 12.5px; }
.transition-table .phase-guess  { color: #d97706; font-weight: 700; font-size: 12.5px; }
.transition-table .phase-pop    { color: #2563eb; font-weight: 700; font-size: 12.5px; }
.transition-table .phase-accept { color: #059669; font-weight: 700; font-size: 12.5px; }
.transition-table em { font-style: italic; color: #d97706; padding: 0 4px; }

/* Trace example block (worked example & student-format reference) */
.trace-example {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-left: 4px solid #94a3b8;
  border-radius: 6px;
  padding: 12px 16px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.85;
  color: #1f2937;
  margin: 10px 0 14px;
  white-space: pre;
  overflow-x: auto;
}
.trace-example .anno {
  color: #d97706;
  font-weight: 700;
  font-family: -apple-system, "Segoe UI", sans-serif;
  font-size: 12px;
  padding: 1px 8px;
  background: #fef3c7;
  border-radius: 4px;
  margin-left: 12px;
  letter-spacing: 0.04em;
}
.trace-example .accept {
  color: #065f46;
  background: #d1fae5;
  font-weight: 700;
  font-family: -apple-system, "Segoe UI", sans-serif;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 4px;
  margin-left: 12px;
  letter-spacing: 0.04em;
}
.trace-example .reject {
  color: #991b1b;
  background: #fee2e2;
  font-weight: 700;
  font-family: -apple-system, "Segoe UI", sans-serif;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 4px;
  margin-left: 12px;
  letter-spacing: 0.04em;
  display: inline-block;
}
.trace-example .reject-reason {
  display: block;
  margin-top: 6px;
  color: #991b1b;
  font-family: -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  white-space: normal;
}
.rich-content .test-strings {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 12px;
}
.rich-content .test-strings code {
  font-size: 14px;
  padding: 4px 10px;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: none; align-items: center; justify-content: center; z-index: 1000;
  padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: white; border-radius: 12px; padding: 32px;
  max-width: 480px; width: 100%; text-align: center;
}
.modal h2 { font-size: 22px; margin-bottom: 12px; color: #dc2626; }
.modal p { color: #4b5563; margin-bottom: 18px; }
.modal .icon { font-size: 48px; margin-bottom: 12px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #e5e7eb; }
th { background: #f9fafb; font-weight: 600; font-size: 13px; color: #374151; }
tr:hover td { background: #f9fafb; }

/* Tabs */
.tabs { display: flex; gap: 8px; border-bottom: 2px solid #e5e7eb; margin-bottom: 16px; }
.tab { padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 500; font-size: 14px; color: #6b7280; }
.tab.active { color: #2563eb; border-bottom-color: #2563eb; }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.actions { display: flex; gap: 8px; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.badge.green { background: #d1fae5; color: #065f46; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.yellow { background: #fef3c7; color: #92400e; }
.badge.gray { background: #f3f4f6; color: #4b5563; }

/* Submit / upload */
.dropzone {
  border: 2px dashed #d1d5db; border-radius: 10px; padding: 30px;
  text-align: center; background: #fafafa; cursor: pointer;
}
.dropzone.over { border-color: #2563eb; background: #eff6ff; }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 10px; margin-top: 12px; }
.preview-grid .thumb { position: relative; border: 1px solid #e5e7eb; border-radius: 6px; overflow: hidden; aspect-ratio: 3/4; background: #f3f4f6; }
.preview-grid .thumb img { width: 100%; height: 100%; object-fit: cover; }
.preview-grid .thumb .x { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.6); color: white; border: 0; width: 22px; height: 22px; border-radius: 50%; cursor: pointer; padding: 0; font-size: 13px; }

/* No-select utility for exam */
.no-select { user-select: none; -webkit-user-select: none; }

/* ============================================================ */
/* Admin: side-by-side editor + live preview                    */
/* ============================================================ */
.editor-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}
.editor-row > div { display: flex; flex-direction: column; }
.editor-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  margin-bottom: 4px;
}
.editor-row textarea {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}
.preview-pane {
  background: #fafbfc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 12px 14px;
  min-height: 100px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 13.5px;
}
.preview-pane:empty::before,
.preview-pane.empty::before {
  content: 'Preview muncul di sini saat Anda mengetik...';
  color: #9ca3af;
  font-style: italic;
  font-size: 12.5px;
}
.format-help {
  background: #eff6ff;
  border-left: 3px solid #2563eb;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 12px;
  color: #1e3a8a;
  margin-bottom: 10px;
}
.format-help code {
  background: white;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11.5px;
  color: #1e40af;
}
.format-help summary { cursor: pointer; font-weight: 600; }

/* Stack on small screens */
@media (max-width: 800px) {
  .editor-row { grid-template-columns: 1fr; }
  .preview-pane { max-height: 250px; }
}

/* ============================================================ */
/* RESPONSIVE — Mobile (≤640px)                                 */
/* ============================================================ */
@media (max-width: 640px) {
  body { font-size: 14px; }

  /* ---- Top bar — stacked layout on mobile ---- */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .topbar .brand { font-size: 14px; text-align: center; }
  .topbar > div:last-child {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px;
  }
  .topbar .info {
    font-size: 12px;
    width: 100%;
    text-align: center;
    order: -1;
    margin-bottom: 2px;
  }
  .timer { font-size: 13px; padding: 4px 10px; }
  .warn-counter { font-size: 12px; padding: 4px 10px; }
  #finishBtn { padding: 8px 12px; font-size: 13px; }

  /* ---- Container / cards ---- */
  .container { padding: 12px; }
  .card { padding: 16px; margin-bottom: 12px; border-radius: 8px; }
  .card h2 { font-size: 16px; }

  /* ---- Buttons — bigger tap targets ---- */
  button {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 14px;
  }
  button.danger, button.secondary, button.success { min-height: 44px; }

  /* ---- Login card ---- */
  .login-card { padding: 24px 20px; }
  .login-card h1 { font-size: 20px; }
  .login-card p.sub { font-size: 13px; }

  /* ---- Inputs — prevent iOS zoom on focus ---- */
  input, textarea, select { font-size: 16px; }

  /* ---- Question items ---- */
  .q-item { padding: 14px 16px; }
  .rich-content { font-size: 14px; line-height: 1.6; }
  .rich-content code { font-size: 0.9em; }

  /* ---- Tables — horizontal scroll wrapper ---- */
  .card table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* Transition table — keep readable, allow horizontal scroll if needed */
  .transition-table {
    display: table;
    font-size: 12.5px;
  }
  .transition-table th { padding: 7px 9px; font-size: 10px; }
  .transition-table td { padding: 7px 9px; }
  .transition-table td:nth-child(1),
  .transition-table td:nth-child(2) { font-size: 12px; }

  /* Wrap transition table in scroll container */
  .rich-content table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ---- Trace example — slightly smaller, scrollable ---- */
  .trace-example {
    font-size: 12px;
    padding: 10px 12px;
    line-height: 1.7;
  }
  .trace-example .anno, .trace-example .accept, .trace-example .reject {
    font-size: 10.5px;
    padding: 1px 6px;
    margin-left: 6px;
    display: inline-block;
  }

  /* ---- Modals ---- */
  .modal-overlay { padding: 14px; }
  .modal { padding: 24px 20px; }
  .modal h2 { font-size: 18px; }
  .modal p { font-size: 14px; }
  .modal .icon { font-size: 40px; }

  /* ---- Submit page ---- */
  .dropzone { padding: 24px 16px; }
  .preview-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }

  /* ---- Admin tabs ---- */
  .tabs { gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { padding: 10px 12px; font-size: 13px; white-space: nowrap; }

  /* ---- Test strings (used in Q3, Q4 lists) ---- */
  .rich-content .test-strings code { font-size: 13px; padding: 4px 8px; }

  /* ---- Forms (admin add-student row) ---- */
  .row { flex-direction: column; gap: 0; }
  .row > * { flex: initial; }

  /* ---- Topbar safe area for notched phones ---- */
  .container, .container.wide { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

/* ============================================================ */
/* PWA — when launched in standalone (installed) mode           */
/* ============================================================ */
@media (display-mode: standalone) {
  body { padding-top: env(safe-area-inset-top); }
  .topbar { padding-top: max(12px, env(safe-area-inset-top)); }
}

/* ============================================================ */
/* RESPONSIVE — Small tablets (641-820px)                       */
/* ============================================================ */
@media (min-width: 641px) and (max-width: 820px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .container { padding: 16px; }
  .card table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
