@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@500;600;700&display=swap');
:root {
  --ui-bg: #f8fafc;
  --ui-surface: rgba(255, 255, 255, 0.85);
  --ui-line: #e2e8f0;
  --ui-text: #1e293b;
  --ui-muted: #64748b;
  --ui-accent: #3b82f6;
}

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

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 64px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
}

.layout-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: var(--ui-surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--ui-line);
  font-family: "Outfit", "Inter", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.layout-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1.3;
  min-width: 0;
  overflow-wrap: anywhere;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-user {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--ui-line);
  background: #f7f7f7;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--ui-muted);
  font-weight: 700;
  text-transform: uppercase;
}
.topbar-user.role-maintainer {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}
.topbar-user.role-reviewer {
  background: #ede9fe;
  border-color: #c4b5fd;
  color: #6d28d9;
}

.topbar-user.role-dept {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0369a1;
}

.topbar-account {
  font-size: 13px;
  color: var(--ui-text);
  font-weight: 600;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-link {
  color: var(--ui-text);
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.25s ease;
}

.topbar-link:hover {
  background: #f1f5f9;
  transform: translateY(-1px);
}

.is-hidden {
  display: none !important;
}

.layout-sidebar {
  grid-area: sidebar;
  background: var(--ui-surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--ui-line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: "Inter", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 14px;
  line-height: 1.4;
  min-width: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.nav-link {
  display: block;
  padding: 10px 14px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--ui-text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  min-width: 0;
  overflow-wrap: anywhere;
  transition: all 0.25s ease;
}

.nav-link:hover {
  background: #f1f5f9;
  transform: translateX(4px);
}

.root-only {
  display: none;
}

body.is-root .root-only {
  display: block;
}

.nav-link.active {
  background: rgba(59, 130, 246, 0.1);
  color: var(--ui-accent);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--ui-accent);
}

.sidebar-footer {
  margin-top: auto;
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--ui-line);
  border-radius: 18px;
  font-size: 13px;
  color: var(--ui-text);
  background: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}

.lang-btn:hover {
  border-color: var(--ui-accent);
}

.lang-btn:hover .lang-icon {
  color: var(--ui-accent);
}

.lang-icon {
  flex: none;
  color: var(--ui-muted);
}

/* i18n.js hides the page until the first English pass to avoid a flash of Chinese. */
html.i18n-pending body {
  visibility: hidden;
}

.layout-main {
  grid-area: main;
  background: transparent;
  padding: 24px 32px 80px;
  min-width: 0;
}

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

/* Hide legacy headers to keep new layout clean */
.appbar {
  display: none !important;
}

/* AI widget */
.ai-widget {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 320px;
  max-width: calc(100vw - 36px);
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  z-index: 999;
}

.ai-widget.is-collapsed .ai-body {
  display: none;
}

.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #f6f6f6;
  border-bottom: 1px solid var(--ui-line);
  font-weight: 700;
}

.ai-body {
  padding: 10px 12px 12px;
  display: grid;
  gap: 8px;
}

.ai-body textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  padding: 8px;
}

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

.ai-btn {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--ui-line);
  background: #fff;
  cursor: pointer;
}

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

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 64px auto 1fr;
    grid-template-areas:
      "topbar"
      "sidebar"
      "main";
  }
  .layout-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--ui-line);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
  }
  .nav-link {
    flex: 1 1 160px;
  }
  .layout-main {
    padding: 20px 20px 72px;
  }
  .sidebar-footer {
    margin-left: auto;
  }
}

@media (max-width: 600px) {
  .layout {
    grid-template-rows: auto auto 1fr;
  }
  .layout-topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 14px 16px 12px;
  }
  .layout-title {
    width: 100%;
    font-size: 17px;
  }
  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 10px;
  }
  .topbar-account {
    max-width: calc(100vw - 120px);
  }
  .layout-sidebar {
    padding: 10px 12px 12px;
  }
  .sidebar-nav {
    gap: 8px;
  }
  .nav-link {
    flex: 1 1 100%;
    text-align: center;
  }
  .sidebar-footer {
    width: 100%;
    margin-left: 0;
  }
  .lang-btn {
    width: 100%;
  }
  .layout-main {
    padding: 16px 12px 96px;
  }
}

/* ─── Excel Preview Styles ─── */
.excel-preview {
  margin-top: 12px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
}
.excel-preview-status {
  padding: 20px;
  text-align: center;
  color: var(--muted, #64748b);
  font-size: 14px;
}
.excel-preview-status.is-error {
  color: #dc2626;
  background: #fef2f2;
  border-radius: 8px;
}
.excel-sheet {
  margin-bottom: 24px;
}
.excel-sheet:last-child {
  margin-bottom: 0;
}
.excel-sheet-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--text, #1e293b);
  border-bottom: 2px solid var(--border, #e2e8f0);
  padding-bottom: 4px;
  display: inline-block;
}
.excel-table-wrap {
  overflow-x: auto;
  max-height: 400px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  background: #fff;
}
.excel-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: var(--text, #1e293b);
}
.excel-table th, .excel-table td {
  border: 1px solid var(--border, #e2e8f0);
  padding: 8px 12px;
  white-space: nowrap;
}
.excel-table th {
  background: #f1f5f9;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}


/* ==== 頂級玻璃擬態確認彈窗 (Custom Confirm Modal) ==== */
.custom-confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  opacity: 0;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-confirm-overlay.is-active {
  opacity: 1;
}

.custom-confirm-modal {
  background: #ffffff;
  border-radius: 20px;
  padding: 32px;
  width: 90%;
  max-width: 400px;
  box-shadow: 
    0 20px 25px -5px rgba(0, 0, 0, 0.1), 
    0 10px 10px -5px rgba(0, 0, 0, 0.04),
    inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(226, 232, 240, 0.8);
  text-align: center;
  transform: scale(0.9) translateY(20px);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.custom-confirm-overlay.is-active .custom-confirm-modal {
  transform: scale(1) translateY(0);
}

.custom-confirm-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #eff6ff;
  color: #3b82f6;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.1);
}

.custom-confirm-icon svg {
  width: 32px;
  height: 32px;
}

.custom-confirm-title {
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 8px 0;
}

.custom-confirm-message {
  font-size: 15px;
  color: #64748b;
  line-height: 1.6;
  margin: 0 0 28px 0;
}

.custom-confirm-buttons {
  display: flex;
  gap: 12px;
}

.custom-confirm-btn {
  flex: 1;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  outline: none;
}

.custom-confirm-btn.cancel {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.custom-confirm-btn.cancel:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.custom-confirm-btn.confirm {
  background: #2563eb;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.custom-confirm-btn.confirm:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(29, 78, 216, 0.3);
}

.custom-confirm-btn.confirm:active {
  transform: translateY(0);
}

/* Certificate name check (cert_check.js) */
.cert-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  vertical-align: middle;
}
.cert-badge.match { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.cert-badge.suspect { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.cert-badge.mismatch { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.cert-badge.not-found { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.reason-cell .cert-badge { margin-right: 6px; }

.cert-files { display: grid; gap: 10px; margin-top: 6px; }
.cert-file {
  padding: 10px 12px;
  border: 1px solid var(--ui-line);
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
  line-height: 1.6;
}
.cert-file-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.cert-file-name { font-weight: 600; color: var(--ui-text); word-break: break-all; }
.cert-method { font-size: 12px; color: var(--ui-muted); }
.cert-name { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cert-quote { margin-top: 4px; color: var(--ui-muted); }
.cert-facts { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; color: var(--ui-muted); font-size: 12px; }
.cert-error { color: #b45309; }
.cert-when { font-size: 12px; color: var(--ui-muted); }
.cert-evidence { margin: 6px 0 0; padding-left: 18px; color: var(--ui-muted); font-size: 13px; }

.dim-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.dim-chip {
  padding: 2px 8px;
  border-radius: 6px;
  background: #eff6ff;
  color: #1e40af;
  font-size: 12px;
}
