:root {
  color-scheme: light;
  --bg: #f6f6f7;
  --surface: #ffffff;
  --brand-bg: #121212;
  --brand-sub: #8f8f92;
  --accent: #f6b800;
  --accent-strong: #f19d00;
  --text: #202020;
  --muted: #6e6e77;
  --muted-light: #9d9da5;
  --border: #e4e4eb;
  --shadow: 0 18px 36px rgba(17, 17, 26, 0.08);
  --radius-lg: 20px;
  --radius-md: 16px;
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
}

* {
  box-sizing: border-box;
}

body.dashboard {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font-family: inherit;
  font-size: 1rem;
}

button {
  cursor: pointer;
}

button:disabled,
button[disabled] {
  cursor: not-allowed;
  opacity: 0.6;
}

.hidden {
  display: none !important;
}

.hero {
  background: var(--brand-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.2rem 2.5vw;
  min-height: 53px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.32);
}

.hero h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  color: var(--accent);
}

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

.brand-image {
  width: clamp(90px, 7vw, 120px);
  height: auto;
}

.container {
  max-width: 1160px;
  margin: 0 auto;
  padding: 2.5rem 3vw;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.section {
  background: var(--surface);
  padding: 1.8rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.section:not(:last-child) {
  margin-bottom: 0.5rem;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.4rem;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.section-title h2 {
  margin: 0;
  font-size: 1.4rem;
}

.section-subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 185, 0, 0.16);
  position: relative;
}

.icon-svg {
  width: 24px;
  height: 24px;
}

.icon-camera::before,
.icon-camera::after {
  content: "";
  position: absolute;
  background: var(--accent);
  border-radius: 2px;
}

.icon-camera::before {
  width: 18px;
  height: 12px;
  top: 10px;
  left: 7px;
}

.icon-camera::after {
  width: 6px;
  height: 6px;
  top: 8px;
  right: 8px;
}

.cctv-grid {
  display: grid;
  gap: 1.4rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.cctv-card,
.add-card {
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: 0 14px 30px rgba(17, 17, 26, 0.05);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
  position: relative;
}

.cctv-card:hover,
.add-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(17, 17, 26, 0.08);
}

.cctv-card.active {
  border: 2px solid var(--accent);
  background: linear-gradient(180deg, rgba(246, 184, 0, 0.04) 0%, #fff 100%);
  box-shadow: 0 0 0 3px rgba(246, 184, 0, 0.12), 0 20px 40px rgba(17, 17, 26, 0.1);
}

/* Yellow top accent bar for active CCTV card */
.cctv-card.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border-radius: 16px 16px 0 0;
  z-index: 10;
}

/* Checkmark icon for active CCTV card - 黃色底黑色勾勾 */
.cctv-card.active .cctv-preview::before {
  content: "✓";
  position: absolute;
  top: 10px;
  left: 10px;
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: var(--brand-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.cctv-preview {
  position: relative;
  height: 140px;
  background: #efefef;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.cctv-preview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cctv-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, 0.45));
  opacity: 0.85;
  pointer-events: none;
  z-index: 1;
}

.cctv-preview span {
  position: absolute;
  bottom: 12px;
  left: 12px;
  color: #fff;
  font-weight: 600;
  z-index: 2;
}

.cctv-menu-trigger {
  position: absolute;
  top: 0.65rem;
  right: 0.55rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  color: #fff;
  font-size: 1.2rem;
}

.cctv-menu-trigger:hover {
  background: rgba(0, 0, 0, 0.6);
}

.cctv-menu {
  position: absolute;
  top: 2.8rem;
  right: 0.8rem;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(16, 24, 40, 0.18);
  border: 1px solid rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  min-width: 150px;
  padding: 0.35rem;
  z-index: 5;
}

.cctv-menu button {
  background: transparent;
  border: none;
  text-align: left;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brand-bg);
}

.cctv-menu button:hover {
  background: rgba(245, 245, 247, 0.9);
  color: var(--accent-strong);
}

.cctv-menu button.danger {
  color: #b3261e;
}

.cctv-menu button.danger:hover {
  color: #e00000;
  background: rgba(224, 0, 0, 0.08);
}

.cctv-body {
  padding: 1rem 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.cctv-info {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.cctv-info h3 {
  margin: 0;
  font-size: 1.05rem;
}

.cctv-info span {
  font-size: 0.85rem;
  color: var(--muted);
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  background: rgba(246, 184, 0, 0.14);
  color: var(--accent-strong);
  font-size: 0.8rem;
  width: fit-content;
}

.cctv-card button {
  margin-top: auto;
}

.add-card {
  border: 2px dashed rgba(246, 184, 0, 0.45);
  background: rgba(255, 255, 255, 0.7);
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}

.add-card span {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--accent);
}

.add-card p {
  margin-top: 0.6rem;
  font-size: 0.95rem;
}

/* Section Divider */
.section-divider {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 0;
  margin: -1rem 0;
}

/* Photo Section Styles */
.photo-grid {
  display: grid;
  gap: 1.4rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.photo-card {
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: 0 14px 30px rgba(17, 17, 26, 0.05);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
  position: relative;
  cursor: pointer;
}

.photo-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(17, 17, 26, 0.08);
}

.photo-card.active {
  border: 2px solid var(--accent);
  background: linear-gradient(180deg, rgba(246, 184, 0, 0.04) 0%, #fff 100%);
  box-shadow: 0 0 0 3px rgba(246, 184, 0, 0.12), 0 20px 40px rgba(17, 17, 26, 0.1);
}

/* Yellow top accent bar for active Photo card */
.photo-card.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border-radius: 16px 16px 0 0;
  z-index: 10;
}

/* Checkmark icon for active Photo card - 黃色底黑色勾勾 */
.photo-card.active .photo-preview::before {
  content: "✓";
  position: absolute;
  top: 10px;
  left: 10px;
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: var(--brand-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.photo-preview {
  position: relative;
  height: 140px;
  background: #efefef;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.photo-preview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-body {
  padding: 1rem 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.photo-info {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.photo-info h3 {
  margin: 0;
  font-size: 1.05rem;
}

.photo-info span {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Photo menu trigger and menu (same as CCTV) */
.photo-menu-trigger {
  position: absolute;
  top: 0.65rem;
  right: 0.55rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  color: #fff;
  font-size: 1.2rem;
}

.photo-menu-trigger:hover {
  background: rgba(0, 0, 0, 0.6);
}

.photo-menu {
  position: absolute;
  top: 2.8rem;
  right: 0.8rem;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(16, 24, 40, 0.18);
  border: 1px solid rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  min-width: 150px;
  padding: 0.35rem;
  z-index: 5;
}

.photo-menu button {
  background: transparent;
  border: none;
  text-align: left;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brand-bg);
}

.photo-menu button:hover {
  background: rgba(245, 245, 247, 0.9);
  color: var(--accent-strong);
}

.photo-menu button.danger {
  color: #b3261e;
}

.photo-menu button.danger:hover {
  color: #e00000;
  background: rgba(224, 0, 0, 0.08);
}

/* Photo preview gradient overlay */
.photo-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, 0.45));
  opacity: 0.85;
  pointer-events: none;
  z-index: 1;
}

.photo-preview span {
  position: absolute;
  bottom: 12px;
  left: 12px;
  color: #fff;
  font-weight: 600;
  z-index: 2;
}

.photo-card button {
  margin-top: auto;
}

/* AI Camera badge - small white text in top-left corner */
.photo-ai-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  bottom: auto;
  right: auto;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  z-index: 3;
}

/* Analysis Preview Section Title */
.analysis-preview-section {
  margin-top: 1.5rem;
}

.analysis-preview-title {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  color: var(--text);
}

.analysis-card {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  background: linear-gradient(150deg, rgba(246, 184, 0, 0.08), rgba(255, 255, 255, 0.98));
  border-radius: var(--radius-md);
  padding: 1.6rem;
  border: 1.5px solid rgba(246, 184, 0, 0.38);
  box-shadow: 0 18px 44px rgba(17, 17, 26, 0.08);
}

.analysis-preview {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: linear-gradient(140deg, #fdfaf2, #f3f4fb);
  border: 1px solid rgba(110, 110, 119, 0.2);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7), 0 10px 28px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  aspect-ratio: 16 / 9;
  max-height: 420px;
  width: 100%;
}

.analysis-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #f9f9fb;
}

.analysis-placeholder {
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  padding: 1.2rem 1rem;
}

.bbox-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bbox-box {
  position: absolute;
  border: 2px solid rgba(241, 157, 0, 0.9);
  border-radius: 14px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.14);
}

.bbox-label {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.16);
}

@media (max-width: 1080px) {
  .analysis-card {
    padding: 1.2rem;
  }
  .analysis-preview {
    max-height: none;
  }
}

.analysis-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

.analysis-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.analysis-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.analysis-meta {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.analysis-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

.analysis-actions .primary,
.analysis-actions .danger {
  min-width: 88px;
}

.analysis-question {
  font-size: 0.95rem;
  color: var(--muted);
}

.analysis-text {
  line-height: 1.7;
  white-space: pre-wrap;
  font-size: 1rem;
  margin: 0;
}

.analysis-editor {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 1rem;
  line-height: 1.6;
  background: #fffefb;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.04);
}

.analysis-editor:disabled,
.analysis-editor[readonly] {
  background: #f7f7f7;
}

.analysis-form {
  margin-top: 1.6rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-items: end;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.question-field {
  gap: 0;
}

.question-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.question-preset {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.question-preset:hover {
  border-color: var(--accent);
}

.question-preset:focus {
  outline: none;
  border-color: var(--accent);
}

.capture-field {
  grid-column: 1 / -1;
}

.capture-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.file-upload-wrapper,
.stream-capture-wrapper {
  flex: 1 1 auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.file-select-btn,
.stream-capture-btn {
  width: 100%;
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius-md);
  border: none;
  background: #1a1a1a;
  color: #f5c542;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

.stream-capture-btn:hover {
  background: #333;
}

.stream-capture-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Auto-refresh controls */
.auto-refresh-wrapper {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #f8f8f8;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-top: 0.5rem;
}

.auto-refresh-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  white-space: nowrap;
}

.auto-refresh-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.auto-refresh-config {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.auto-refresh-input {
  width: 70px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  text-align: center;
}

.auto-refresh-input:focus {
  outline: none;
  border-color: var(--accent);
}

.auto-refresh-select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fff;
  cursor: pointer;
}

.auto-refresh-select:focus {
  outline: none;
  border-color: var(--accent);
}

.auto-refresh-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.auto-refresh-countdown {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 80px;
}

.auto-refresh-countdown.active {
  color: var(--accent-strong);
  font-weight: 500;
}

.manual-refresh-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.manual-refresh-btn:hover {
  background: var(--accent-strong);
  transform: rotate(180deg);
}

.manual-refresh-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.manual-refresh-btn.refreshing {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.form-field label {
  font-size: 0.9rem;
  color: var(--muted);
}

.form-field input,
.form-field textarea {
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #fafafa;
}

.form-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.8rem;
  justify-content: flex-end;
}

.primary,
.secondary,
.ghost {
  border-radius: 999px;
  padding: 0.65rem 1.4rem;
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

.primary {
  background: var(--brand-bg);
  color: var(--accent);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.36);
}

.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.46);
}

.secondary {
  background: var(--brand-bg);
  color: var(--accent);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
}

.secondary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4);
}

.ghost {
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  border-color: transparent;
}

.ghost:hover:not(:disabled) {
  color: var(--accent);
}

.danger {
  border-radius: 999px;
  padding: 0.65rem 1.4rem;
  border: 1px solid rgba(17, 17, 17, 0.55);
  font-size: 0.95rem;
  font-weight: 600;
  background: rgba(246, 184, 0, 0.08);
  color: rgba(17, 17, 17, 0.55);
  box-shadow: 0 5px 12px rgba(246, 184, 0, 0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

.danger:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(246, 184, 0, 0.22);
}

/* ===== Button Loading State ===== */
.primary.loading,
.secondary.loading,
.outline.loading,
.danger.loading {
  pointer-events: none;
  opacity: 0.85;
}

.primary.loading::after,
.secondary.loading::after,
.outline.loading::after,
.danger.loading::after {
  content: "";
  display: inline-block;
  width: 1rem;
  height: 1rem;
  margin-left: 0.5rem;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
  vertical-align: middle;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* Storage Filter */
.section-heading-left {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.storage-filter {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.filter-btn.active {
  background: var(--brand-bg);
  color: var(--accent);
  border-color: var(--brand-bg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

@media (max-width: 640px) {
  .storage-filter {
    width: 100%;
    justify-content: flex-start;
  }

  .filter-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }
}

.storage-grid {
  display: grid;
  gap: 1.2rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.storage-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 10px 26px rgba(17, 17, 26, 0.06);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
  position: relative;
  overflow: hidden;
}

.storage-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 32px rgba(17, 17, 26, 0.1);
}

.storage-card.active {
  border: 2px solid var(--accent);
  background: linear-gradient(180deg, rgba(246, 184, 0, 0.04) 0%, #fff 100%);
  box-shadow: 0 0 0 3px rgba(246, 184, 0, 0.12), 0 20px 40px rgba(17, 17, 26, 0.1);
}

/* Yellow top accent bar for active Storage card */
.storage-card.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border-radius: 16px 16px 0 0;
  z-index: 10;
}

/* Checkmark icon for active Storage card - 黃色底黑色勾勾 */
.storage-card.active::after {
  content: "✓";
  position: absolute;
  top: 10px;
  left: 10px;
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: var(--brand-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.storage-card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: #e9eaf0;
}

.storage-thumb {
  width: 100%;
  height: 150px;
  border-radius: var(--radius-md);
  background: repeating-linear-gradient(
    -45deg,
    rgba(0, 0, 0, 0.05),
    rgba(0, 0, 0, 0.05) 12px,
    rgba(0, 0, 0, 0.08) 12px,
    rgba(0, 0, 0, 0.08) 24px
  );
}

.storage-card h3 {
  margin: 0;
  font-size: 1rem;
}

.storage-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.storage-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted-light);
}

.report-section {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.report-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 1000;
}

.modal-panel {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 22px;
  padding: 2rem;
  position: relative;
  box-shadow: 0 30px 60px rgba(17, 17, 26, 0.28);
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.modal-panel.small {
  width: min(440px, 100%);
}

.modal-panel.wide {
  width: min(820px, 100%);
}

.modal-panel h3 {
  margin: 0;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1.1rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  color: var(--muted);
  border: none;
  font-size: 1.1rem;
  line-height: 1;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.12);
}

.modal-description {
  margin: 0 0 0.6rem;
  font-size: 0.92rem;
  color: var(--muted);
}

.modal-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
  align-items: stretch;
}

.modal-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-section h4 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-divider {
  display: none;
}

.modal-panel.wide .modal-divider {
  display: none;
}

@media (min-width: 760px) {
  .modal-panel.wide .modal-columns {
    grid-template-columns: minmax(0, 1fr) 1px minmax(0, 1fr);
  }

  .modal-panel.wide .modal-divider {
    display: block;
    width: 1px;
    background: rgba(0, 0, 0, 0.08);
  }
}

/* Inspection view modal */
.inspection-view-panel {
  width: min(800px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
}

.inspection-view-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.inspection-view-header h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1.25rem;
}

.inspection-view-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.inspection-view-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.inspection-view-image {
  max-width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: var(--radius-md);
  background: #f0f0f0;
}

.inspection-view-question {
  margin: 0;
  padding: 0.75rem 1rem;
  background: rgba(246, 184, 0, 0.1);
  border-radius: var(--radius-md);
  color: var(--text);
  font-weight: 500;
}

.inspection-view-question:empty {
  display: none;
}

.inspection-view-text {
  white-space: pre-wrap;
  line-height: 1.7;
  color: var(--text);
  font-size: 0.95rem;
  max-height: 400px;
  overflow-y: auto;
  padding: 1rem;
  background: #fafafa;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.local-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.local-form .form-actions {
  justify-content: space-between;
}

.template-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.template-card,
.template-add {
  border: 1px dashed rgba(0, 0, 0, 0.12);
  border-radius: 16px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: border 0.2s ease, transform 0.2s ease;
}

.template-card:hover,
.template-add:hover {
  transform: translateY(-2px);
}

.template-card.active {
  border: 2px solid var(--accent);
}

.template-card span {
  font-weight: 600;
  color: var(--text);
}

.template-card p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Hide system-managed image fields in Template Three form */
.form-field[data-key^="image:before"],
.form-field[data-key^="image:after"],
.form-field[data-key^="image:beore"] {
  display: none !important;
}

.template-add span {
  font-size: 2.4rem;
  color: var(--accent);
}

.template-create {
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: var(--radius-md);
  background: #fafafa;
}

.template-create h4 {
  margin: 0 0 0.8rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.8rem;
}

.modal-footer.split {
  justify-content: space-between;
  align-items: center;
}

.danger-text {
  color: #b3261e !important;
}

.danger-text:hover {
  color: #e00000 !important;
}

.camera-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auto-analyze-toggle {
  display: flex;
  align-items: center;
}

.auto-analyze-toggle label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  user-select: none;
}

.auto-analyze-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.interval-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.interval-input-group.hidden {
  display: none;
}

.interval-input-group label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.interval-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.interval-row input[type="number"] {
  width: 100px;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.interval-unit {
  font-size: 0.9rem;
  color: var(--muted);
}

.auto-analyze-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: rgba(246, 184, 0, 0.12);
  color: #b8860b;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  align-self: flex-start;
}

@media (max-width: 920px) {
  .analysis-card {
    grid-template-columns: 1fr;
  }

  .analysis-preview {
    min-height: 200px;
  }

  .analysis-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.8rem;
  }

  .report-actions {
    flex-direction: column;
    align-items: flex-start;
  }

  .analysis-form {
    grid-template-columns: 1fr;
  }
}
