:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --accent: #f59e0b;
  --accent-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --success: #10b981;
  --success-light: #d1fae5;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 16px;
  --nav-height: 64px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-subtle: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary: #38bdf8;
  --primary-light: #082f49;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

body {
  background-color: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
  padding-bottom: calc(var(--nav-height) + 24px);
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
[data-theme="dark"] .app-header {
  background: rgba(30, 41, 59, 0.85);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  font-size: 26px;
  background: var(--primary-light);
  padding: 6px;
  border-radius: 12px;
}
.brand-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Redlines banner */
.redlines-container {
  padding: 12px 16px 4px 16px;
}
.redline-badge-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.redline-badge-bar::-webkit-scrollbar {
  display: none;
}
.redline-pill {
  flex-shrink: 0;
  background: var(--danger-light);
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

/* Search bar */
.search-wrapper {
  padding: 12px 16px;
}
.search-input-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 14px;
  font-size: 16px;
  color: var(--text-muted);
}
.search-input {
  width: 100%;
  padding: 12px 14px 12px 40px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  box-shadow: var(--shadow);
  transition: all 0.2s;
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

/* Category Filter Tabs */
.tabs-scroll {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-scroll::-webkit-scrollbar {
  display: none;
}
.tab-btn {
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);
}

/* Content Views */
.view-panel {
  display: none;
  padding: 0 16px;
}
.view-panel.active {
  display: block;
}

/* Section Cards */
.spec-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}
.spec-card:active {
  transform: scale(0.99);
}
.spec-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.spec-title-group h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}
.spec-title-en {
  font-size: 12px;
  color: var(--text-muted);
}
.vcm-page-tag {
  font-size: 11px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  padding: 4px 8px;
  border-radius: 8px;
  white-space: nowrap;
}
.spec-doc-no {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
  margin-bottom: 8px;
}
.spec-summary {
  font-size: 13px;
  color: var(--text-main);
  margin-bottom: 12px;
}

/* Quick Action Buttons */
.quick-buttons-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}
.quick-action-btn {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.quick-action-btn:active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Key Rules List */
.rules-list {
  list-style: none;
}
.rules-list li {
  font-size: 12.5px;
  color: var(--text-muted);
  position: relative;
  padding-left: 14px;
  margin-bottom: 6px;
  line-height: 1.45;
}
.rules-list li::before {
  content: "•";
  position: absolute;
  left: 2px;
  color: var(--primary);
  font-weight: bold;
}

/* Carton Visual Box (Interactive) */
.carton-visual-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.carton-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.carton-face-btn {
  flex: 1;
  padding: 8px 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  cursor: pointer;
}
.carton-face-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.carton-display-box {
  background: #fdf6e2;
  border: 2px solid #b45309;
  border-radius: 12px;
  padding: 16px;
  min-height: 240px;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
}
[data-theme="dark"] .carton-display-box {
  background: #292524;
  border-color: #78716c;
}
.carton-face-content {
  display: none;
}
.carton-face-content.active {
  display: block;
}

.carton-mark-item {
  background: rgba(255, 255, 255, 0.9);
  border: 1px dashed #78350f;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #451a03;
  cursor: pointer;
  transition: all 0.2s;
}
[data-theme="dark"] .carton-mark-item {
  background: rgba(68, 64, 60, 0.9);
  color: #fef3c7;
  border-color: #a8a29e;
}
.carton-mark-item:hover, .carton-mark-item:active {
  background: var(--accent-light);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.mark-title {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.mark-desc {
  font-size: 11px;
  color: #78350f;
}
[data-theme="dark"] .mark-desc {
  color: #d6d3d1;
}

/* Calculator Cards */
.calc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.calc-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.calc-input-group {
  margin-bottom: 12px;
}
.calc-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-muted);
}
.calc-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
}
.calc-input:focus {
  border-color: var(--primary);
}
.calc-btn {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}
.calc-result-box {
  margin-top: 14px;
  background: var(--surface-subtle);
  border-left: 4px solid var(--primary);
  padding: 12px;
  border-radius: 0 8px 8px 0;
  display: none;
}
.calc-result-box.show {
  display: block;
}
.calc-result-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.calc-result-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
}
.calc-result-tip {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Checklist */
.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
}
.checklist-check {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}
.checklist-content {
  flex: 1;
}
.checklist-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 2px;
}
.checklist-ref {
  font-size: 11px;
  color: var(--text-muted);
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom);
}
[data-theme="dark"] .bottom-nav {
  background: rgba(15, 23, 42, 0.92);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
  transition: color 0.15s;
}
.nav-item.active {
  color: var(--primary);
}
.nav-icon {
  font-size: 20px;
}

/* Modal Popup */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 300;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.active {
  display: flex;
}
.modal-content {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
}
.modal-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

/* Offline & Network Pill */
.offline-pill {
  font-size: 11px;
  font-weight: 700;
  background: var(--success-light);
  color: var(--success);
  padding: 4px 8px;
  border-radius: 12px;
  white-space: nowrap;
}

/* Clear Search Button */
.clear-search-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}

/* Rendered Markdown Styling */
.markdown-rendered-view table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 12px;
}
.markdown-rendered-view th, .markdown-rendered-view td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}
.markdown-rendered-view th {
  background: var(--surface-subtle);
  font-weight: 700;
}
.markdown-rendered-view ul, .markdown-rendered-view ol {
  margin-left: 20px;
  margin-bottom: 8px;
}
.markdown-rendered-view li {
  margin-bottom: 4px;
}
.markdown-rendered-view strong {
  color: var(--text-main);
}
