/* v2 UI is opt-in via html[data-ui="v2"] */

html[data-ui="v2"] {
  /* Design tokens */
  --bg: #f6f8fa;
  --card: #ffffff;
  --panel-shadow: rgba(0, 0, 0, 0.12);
  --accent: #16a34a; /* emerald-600 */
  --accent-light: #dcfce7; /* emerald-100 */
  --text: #111827; /* gray-900 */
  --muted: #6b7280; /* gray-500 */
  --border-radius: 14px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-ui="v2"] body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
}

/* Accordion chevron */
html[data-ui="v2"] details.accordion summary::before {
  content: "▶";
  color: var(--accent);
}
html[data-ui="v2"] details.accordion[open] summary::before { transform: rotate(90deg); }

/* Cards */
html[data-ui="v2"] details.accordion {
  border-radius: var(--border-radius);
  box-shadow: 0 6px 16px var(--panel-shadow);
}

/* Tables */
html[data-ui="v2"] table {
  border-radius: var(--border-radius);
  box-shadow: 0 3px 10px var(--panel-shadow);
}
html[data-ui="v2"] th { background: #f3f4f6; }
html[data-ui="v2"] tbody tr:nth-child(odd) { background: #fafafa; }

/* Buttons */
html[data-ui="v2"] button,
html[data-ui="v2"] .action-btn {
  border-radius: var(--border-radius);
}

/* HUD */
html[data-ui="v2"] #hud-bar { box-shadow: 0 -4px 12px var(--panel-shadow); }
html[data-ui="v2"] #hud-bar button { color: var(--muted); }
html[data-ui="v2"] #hud-bar button.active,
html[data-ui="v2"] #hud-bar button:hover { color: var(--accent); }

/* Settings panel */
html[data-ui="v2"] #settings-menu {
  border-color: var(--accent);
  animation: fadeIn 0.25s ease-in-out;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  html[data-ui="v2"] {
    --bg: #0b1220;
    --card: #111827;
    --panel-shadow: rgba(0,0,0,0.6);
    --accent: #22c55e;
    --accent-light: #052e16;
    --text: #e5e7eb;
    --muted: #9ca3af;
  }
  html[data-ui="v2"] th { background: #1f2937; }
  html[data-ui="v2"] tbody tr:nth-child(odd) { background: #111827; }
}

/* v2 settings drawer + overlay */
html[data-ui="v2"] #settings-menu > summary { display: none; }
html[data-ui="v2"] #settings-menu {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  margin: 0;
  border-radius: 0;
  border-left: 2px solid var(--accent);
  box-shadow: -8px 0 24px var(--panel-shadow);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  padding-top: 1rem;
  z-index: 1001;
}
html[data-ui="v2"] #settings-menu[open] { transform: translateX(0); }
html[data-ui="v2"] #drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(1px);
  z-index: 1000;
  display: none;
}
html[data-ui="v2"] #drawer-overlay[data-open="true"] { display: block; }

/* Sticky table header */
html[data-ui="v2"] #entries-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Form layout improvements */
html[data-ui="v2"] #sale-form,
html[data-ui="v2"] #strain-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px 16px;
}
html[data-ui="v2"] #sale-form button[type="submit"],
html[data-ui="v2"] #strain-form button[type="submit"] { grid-column: 1 / -1; }
html[data-ui="v2"] #sale-form #grams { width: calc(100% - 96px); display: inline-block; }
html[data-ui="v2"] #sale-form #sale-unit { width: 90px; display: inline-block; margin-left: 6px; }
html[data-ui="v2"] #strain-form #new-stock { width: calc(100% - 96px); display: inline-block; }
html[data-ui="v2"] #strain-form #stock-unit { width: 90px; display: inline-block; margin-left: 6px; }
@media (max-width: 640px) {
  html[data-ui="v2"] #sale-form,
  html[data-ui="v2"] #strain-form { grid-template-columns: 1fr; }
}

/* Robust chevron using borders (override any earlier content-based icons) */
html[data-ui="v2"] details.accordion summary::before {
  content: "" !important;
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  border-right: 2px solid var(--accent);
  border-top: 2px solid var(--accent);
  margin-right: 0.5em;
  transform: rotate(45deg) !important;
}
html[data-ui="v2"] details.accordion[open] summary::before { transform: rotate(135deg) !important; }

/* Ensure chevron renders correctly in v2 */
html[data-ui="v2"] details.accordion summary::before { content: "▶" !important; }
