:root {
  color-scheme: dark;

  --bg: #0f1117;
  --surface: #1a1d27;
  --card: #21253a;
  --accent2: #43e97b;
  --text: #e8eaf6;
  --muted: #d0d4de;
  --border: #2e3250;
  --danger: #ff6b6b;
  --warn: #ffd166;

  /* Spacing scale */
  --s1: 0.1rem;
  --s2: 0.2rem;
  --s3: 0.3rem;
  --s4: 0.38rem;
  --s5: 0.45rem;
  --s6: 0.55rem;
  --s7: 0.65rem;
  --s8: 0.75rem;
  --s9: 0.9rem;
  --s10: 1rem;
  --s11: 1.1rem;
  --s12: 1.25rem;
  --s13: 1.5rem;

  /* Border radius scale */
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --radius-xs: 2px;
  --radius-sm-md: 6px;
  --radius-pill: 99px;
  --radius-circle: 50%;
  --radius-icon: 15px;

  /* Shadow & overlay tokens */
  --shadow-light: rgba(0, 0, 0, 0.14);
  --shadow-medium: rgba(0, 0, 0, 0.18);
  --shadow-strong: rgba(0, 0, 0, 0.22);
  --shadow-dark: rgba(0, 0, 0, 0.55);
  --shadow-heavy: rgba(0, 0, 0, 0.7);
  --shadow-card: rgba(0, 0, 0, 0.25);
  --overlay-modal: rgba(0, 0, 0, 0.6);
  --overlay-bg: rgba(0, 0, 0, 0.44);

  /* Accent-derived tokens */
  --accent2-bg-subtle: color-mix(in srgb, var(--accent2) 7%, transparent);
  --accent2-border-subtle: color-mix(in srgb, var(--accent2) 20%, transparent);
  --on-accent: #000;
  --on-danger: #fff;

  /* White overlay tokens (for buttons on accent backgrounds) */
  --white-overlay-light: rgba(255, 255, 255, 0.2);
  --white-overlay-medium: rgba(255, 255, 255, 0.3);
  --white-overlay-strong: rgba(255, 255, 255, 0.4);

  /* Widget size tokens */
  --widget-min-sm: 80px;
  --widget-min-compact: 100px;
  --widget-min-standard: 160px;
  --widget-min-expanded: 240px;

  /* Warning state tokens (derived from --warn) */
  --warn-bg: rgba(255, 209, 102, 0.12);
  --warn-border: rgba(255, 209, 102, 0.25);

  /* Line height & dot sizes */
  --lh: 1.6;
  --dot-sm: 5px;
  --dot-md: 7px;
  --dot-lg: 9px;

  /* Structural sizes */
  --nav-height: 52px;
  --notif-popup-w: 310px;
  --notif-popup-max-h: 260px;
  --tooltip-width: 260px;
  --swipe-width: 70px;
  --swipe-width-narrow: 60px;
  --badge-size: 10px;
  --icon-sm: 16px;
  --icon-md: 18px;
  --icon-lg: 20px;
  --icon-nav: 23px;
  --content-max-w: 960px;

  /* Toggle sizes */
  --toggle-knob: #fff;
  --toggle-width: 40px;
  --toggle-height: 22px;
  --toggle-shift: 18px;

  /* Letter spacing */
  --tracking-sm: 0.3px;
  --tracking-md: 0.5px;
  --tracking-lg: 0.6px;

  /* Animation & transition timing tokens */
  --transition-fast: 0.12s;
  --transition-base: 0.2s;
  --transition-slow: 0.35s;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

/* Scroll fade indicators — horizontal overflow hint (Issue #20) */
.scroll-fade-x {
  position: relative;
}

.scroll-fade-x::before,
.scroll-fade-x::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.scroll-fade-x::before {
  left: 0;
  background: linear-gradient(to right, var(--bg), transparent);
}

.scroll-fade-x::after {
  right: 0;
  background: linear-gradient(to left, var(--bg), transparent);
}

.scroll-fade-x.can-scroll-right::after,
.scroll-fade-x.can-scroll-left::before {
  opacity: 1;
}

/* Scroll fade indicators — vertical overflow hint */
.scroll-fade-y {
  position: relative;
}

.scroll-fade-y::before,
.scroll-fade-y::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 24px;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.scroll-fade-y::before {
  top: 0;
  background: linear-gradient(to bottom, var(--surface), transparent);
}

.scroll-fade-y::after {
  bottom: 0;
  background: linear-gradient(to top, var(--surface), transparent);
}

.scroll-fade-y.can-scroll-down::after,
.scroll-fade-y.can-scroll-up::before {
  opacity: 1;
}

html {
  touch-action: pan-x pan-y;
  width: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  width: 100%;
  min-height: 100vh;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

input,
textarea,
select {
  user-select: text;
}

/* ════════════════════════════════════════════════════════════════════
   UTILITY CLASSES (Issue #296)
   ═══════════════════════════════════════════════════════════════════ */

/* Flexbox utilities */
.flex {
  display: flex;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.flex-gap-sm {
  gap: var(--s5);
}

.flex-gap-md {
  gap: var(--s9);
}

/* Text alignment */
.text-center {
  text-align: center;
}

/* Spacing utilities */
.mb-sm {
  margin-bottom: var(--s5);
}

.mb-md {
  margin-bottom: var(--s9);
}

.mt-sm {
  margin-top: 0.6rem;
}

.p-card {
  padding: var(--s13) var(--s10);
}

.p-sm {
  padding: var(--s7) var(--s8) var(--s5);
}

.p-md {
  padding: var(--s8);
}

/* Visibility */
.hidden {
  display: none;
}

/* Ensure hidden overlays don't block pointer events */
.modal-overlay.hidden {
  pointer-events: none;
}

/* Fix: Ensure all overlays stay hidden when .hidden class is present
   (prevents display:flex from overlay classes overriding display:none)
   This fixes CSS specificity conflicts for all fixed-position overlays */
.notif-panel.hidden,
.notif-detail-overlay.hidden,
.modal-overlay.hidden,
.emoji-overlay.hidden,
.emoji-popup.hidden,
.form-popup-overlay.hidden {
  display: none !important;
}

/* Margins */
.m-0 {
  margin: 0;
}

/* Emoji Picker Components */
.emoji-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1800;
  background: var(--overlay-bg);
}

.emoji-popup {
  display: none;
  position: fixed;
  z-index: 1801;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px #000a;
  width: min(340px, 92vw);
  max-height: 420px;
  overflow: hidden;
  flex-direction: column;
}

.emoji-search-container {
  padding: var(--s7) var(--s8) var(--s5);
  border-bottom: 1px solid var(--border);
}

.emoji-search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: var(--s5) var(--s7);
  font-size: 0.84rem;
}

.emoji-cat-tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  padding: var(--s5) var(--s6) var(--s3);
  gap: 0.18rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.emoji-grid {
  overflow: auto hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: var(--s6);
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 2.4rem;
  gap: 0.18rem;
  flex-shrink: 0;
}

/* Import/Export Components */
.export-import-text {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
}

.json-textarea {
  width: 100%;
  min-height: 300px;
  font-family: monospace;
  font-size: 0.72rem;
  padding: var(--s6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.copy-notice {
  display: none;
  color: var(--accent2);
  font-size: 0.75rem;
  margin-top: 0.5rem;
}

/* ════════════════════════════════════════════════════════════════════ */

/* SMART SETTINGS TOGGLES */
.setting-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s10);
  padding: var(--s8) 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.setting-row-disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

.setting-label {
  flex: 1;
  min-width: 0;
}

.setting-label strong {
  font-size: 0.82rem;
  font-weight: 700;
  display: block;
  margin-bottom: var(--s1);
}

.setting-label span {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.5;
}

.setting-right {
  display: flex;
  align-items: center;
  gap: var(--s6);
  flex-shrink: 0;
}

/* pill toggle */
.sw {
  position: relative;
  width: var(--toggle-width);
  height: var(--toggle-height);
  flex-shrink: 0;
}

.sw input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.sw-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: var(--radius-pill);
  transition: background var(--transition-base);
  cursor: pointer;
}

.sw input:checked + .sw-track {
  background: var(--accent2);
}

.sw-track::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: var(--toggle-knob);
  border-radius: var(--radius-circle);
  top: 3px;
  left: 3px;
  transition: transform var(--transition-base);
}

.sw input:checked + .sw-track::after {
  transform: translateX(var(--toggle-shift));
}

/* info bubble */
.info-bubble {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-circle);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
  overflow: visible;
}

.info-bubble.open .info-tooltip {
  display: block;
}

.info-tooltip {
  display: none;
  position: absolute;
  right: calc(100% + var(--s8));
  top: 50%;
  transform: translateY(-50%);
  width: var(--tooltip-width);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--s7) var(--s8);
  font-size: 0.7rem;
  color: var(--text);
  line-height: var(--lh);
  z-index: 9999;
  box-shadow: 0 6px 24px #000a;
  white-space: normal;
  pointer-events: none;
}

.info-tooltip .tip-desc {
  margin-bottom: 0;
}

.info-tooltip .conflict-note {
  color: var(--warn);
  margin-top: var(--s6);
  padding-top: var(--s5);
  border-top: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.68rem;
  line-height: var(--lh);
}

/* Skip link — visually hidden until focused (H-A11Y-08) */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  padding: var(--s6) var(--s10);
  background: var(--accent2);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.875rem;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 10000;
  text-decoration: none;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

nav {
  position: relative;
  z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(var(--nav-height) + env(safe-area-inset-top, 0px));
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--s2));
  padding-bottom: var(--s6);
  box-shadow: 0 2px 12px #0005;
}

.nav-brand {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: var(--tracking-sm);
  pointer-events: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
}

.nav-brand .brand-better {
  color: var(--text);
}

.nav-brand .brand-choices {
  color: var(--accent2);
}

/* BOTTOM NAV */
.bottom-nav {
  position: fixed;
  inset: auto 0 0;
  z-index: 100;
  background: var(--card);
  border-top: 1px solid var(--border);
  border-bottom: none;
  display: flex;
  align-items: stretch;
  padding-top: var(--s5);
  padding-bottom: max(var(--s5), env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -2px 16px #0007;
  min-height: calc(58px + env(safe-area-inset-bottom, 0px));
}

.bnav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: var(--s8) 0 var(--s8) 0;
  transition: color var(--transition-fast);
}

.bnav-tab svg {
  width: var(--icon-nav);
  height: var(--icon-nav);
  flex-shrink: 0;
  stroke: currentcolor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bnav-tab span {
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-lg);
}

.bnav-tab.active {
  color: var(--accent2);
}

.bnav-tab:hover:not(.active) {
  color: var(--text);
}

/* TOP NAV BACK BUTTON */
.topnav-back-btn {
  position: absolute;
  left: var(--s8);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: var(--s10);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.topnav-back-btn:hover {
  background: var(--surface);
}

.topnav-back-btn svg {
  stroke: currentcolor;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* PANEL BACK BUTTON (inline variant of topnav-back-btn for full-screen panels) */
.panel-icon-back {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: var(--s10);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.panel-icon-back:hover {
  background: var(--surface);
}

.panel-icon-back svg {
  stroke: currentcolor;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* NOTIFICATION BELL */
.notif-bell {
  position: absolute;
  right: var(--s8);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: var(--s10);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-circle);
  transition: background var(--transition-fast);
}

.notif-bell:hover {
  background: var(--surface);
}

.notif-bell svg {
  width: var(--icon-lg);
  height: var(--icon-lg);
  stroke: currentcolor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.notif-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--danger);
  border-radius: var(--radius-circle);
  width: var(--badge-size);
  height: var(--badge-size);
  border: 1.5px solid var(--card);
}

/* NOTIFICATION DROPDOWN */
.notif-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0.5rem;
  width: min(var(--notif-popup-w), 92vw);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px #000c;
  z-index: 500;
  overflow: hidden;
  display: none;
}

.notif-dropdown.open {
  display: block;
}

.notif-drop-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s7) var(--s9);
  border-bottom: 1px solid var(--border);
}

.notif-drop-hdr span {
  font-size: 0.78rem;
  font-weight: 700;
}

.notif-drop-viewall {
  background: none;
  border: none;
  color: var(--accent2);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: var(--s2) var(--s3);
}

.notif-drop-list {
  max-height: var(--notif-popup-max-h);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: var(--s6);
  padding: var(--s7) var(--s9);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}

.notif-item:last-child {
  border-bottom: none;
}

.notif-item:hover {
  background: var(--surface);
}

.notif-item-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  margin-top: var(--s1);
}

.notif-item-body {
  flex: 1;
  min-width: 0;
}

.notif-item-title {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--s1);
}

.notif-item-preview {
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notif-item-date {
  font-size: 0.6rem;
  color: var(--muted);
  margin-top: var(--s1);
}

.notif-item-dot {
  width: var(--dot-md);
  height: var(--dot-md);
  border-radius: var(--radius-circle);
  background: var(--accent2);
  flex-shrink: 0;
  margin-top: 5px;
}

.notif-empty {
  text-align: center;
  padding: var(--s12);
  font-size: 0.78rem;
  color: var(--muted);
}

/* NOTIFICATION PANEL + DETAIL */
.notif-panel {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.notif-panel.open {
  transform: translateX(0);
}

.notif-panel-hdr {
  display: flex;
  align-items: center;
  gap: var(--s8);
  padding: var(--s9) var(--s10);
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.notif-panel-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: var(--s2) var(--s6);
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.notif-panel-back:hover {
  background: var(--border);
  color: var(--text);
}

.notif-panel-title {
  font-size: 0.95rem;
  font-weight: 800;
  flex: 1;
}

.notif-panel-markall {
  background: none;
  border: none;
  color: var(--accent2);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.notif-panel-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--s8);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.notif-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 1600;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.notif-detail-overlay.open {
  transform: translateX(0);
}

.notif-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--s10);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.notif-drop-list::-webkit-scrollbar,
.notif-panel-list::-webkit-scrollbar,
.notif-detail-body::-webkit-scrollbar {
  display: none;
  width: 0;
}

/* LAYOUT */
main {
  max-width: var(--content-max-w);
  margin: 0 auto;
  padding: var(--s12) var(--s8) calc(68px + env(safe-area-inset-bottom, 0px) + var(--s12));
}

section {
  display: none;
}

section.active {
  display: block;
}

h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: var(--s10);
}

h3 {
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: var(--s6);
  font-weight: 700;
}

/* CARDS */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s11);
  margin-bottom: var(--s10);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s8);
}

@media (width <= 480px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* FORMS */
label {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  margin-bottom: var(--s2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-md);
}

input:not(
  [type='hidden'],
  [type='checkbox'],
  [type='radio'],
  [type='submit'],
  [type='button'],
  [type='range']
),
select {
  width: 100%;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: var(--s7) var(--s9);
  font-size: 0.9rem;
  line-height: 1;
  min-height: 2.75rem;
  transition: border-color var(--transition-base);
  appearance: none;
}

input[type='”date”']::-webkit-calendar-picker-indicator {
  filter: invert(0.6);
}

input:not(
    [type='”hidden”'],
    [type='”checkbox”'],
    [type='”radio”'],
    [type='”submit”'],
    [type='”button”'],
    [type='”range”']
  ):focus,
select:focus {
  outline: none;
  border-color: var(--accent2);
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  box-shadow: 0 0 0 1000px var(--surface) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%2343e97b' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 12px 8px;
  padding-right: 2.4rem;
}

.btn {
  padding: var(--s5) var(--s9);
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    opacity 0.2s,
    transform 0.1s;
  white-space: nowrap;
  transform: translateZ(0);
}

.btn:active {
  transform: scale(0.97) translateZ(0);
}

.btn-primary {
  background: var(--accent2);
  color: var(--bg); /* Issue #281: Use design token instead of hardcoded #000 */
}

.btn-success {
  background: var(--accent2);
  color: var(--bg); /* Issue #281: Use design token instead of hardcoded #000 */
}

.btn-danger {
  background: var(--danger);
  color: var(--text); /* Issue #281: Use design token instead of hardcoded #fff */
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.btn-sm {
  padding: var(--s3) var(--s6);
  font-size: 0.75rem;
}

.btn:hover {
  opacity: 0.85;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Issue #4: Generic loading states — reusable across all async operations */
.me-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: widget-spin 0.8s linear infinite;
  will-change: transform;
  display: inline-block;
  vertical-align: middle;
}

.me-spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

.btn-loading {
  pointer-events: none;
  opacity: 0.7;
  position: relative;
}

.btn-loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid currentcolor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: widget-spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
  margin-left: var(--s4);
}

/* Loading overlay for containers (settings sections, module areas) */
.me-loading-overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: inherit;
}

/* Toggle switch loading state */
.toggle-loading {
  pointer-events: none;
  opacity: 0.5;
}

/* STATS */
.stats-row {
  display: flex;
  gap: var(--s7);
  margin-bottom: var(--s10);
  flex-wrap: wrap;
}

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--s7) var(--s9);
  flex: 1;
  min-width: 110px;
  text-align: center;
}

.stat-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent2);
}

.stat-label {
  font-size: 0.6rem;
  color: var(--muted);
  margin-top: var(--s1);
  text-transform: uppercase;
  letter-spacing: var(--tracking-sm);
}

/* ALERT / INFO */
.info-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: var(--s6) var(--s8);
  font-size: 0.75rem;
  color: var(--muted);
  line-height: var(--lh);
}

.info-box strong {
  color: var(--text);
}

.alert {
  border-radius: var(--radius-sm);
  padding: var(--s6) var(--s9);
  font-size: 0.75rem;
  line-height: var(--lh);
  font-weight: 600;
}

.alert-danger {
  background: color-mix(in srgb, var(--danger) 10%, transparent); /* Issue #281 */
  border: 1px solid color-mix(in srgb, var(--danger) 27%, transparent);
  color: var(--danger);
}

.alert-warn {
  background: color-mix(in srgb, var(--warn) 10%, transparent); /* Issue #281 */
  border: 1px solid color-mix(in srgb, var(--warn) 27%, transparent);
  color: var(--warn);
}

.alert-ok {
  background: color-mix(in srgb, var(--accent2) 10%, transparent); /* Issue #281 */
  border: 1px solid color-mix(in srgb, var(--accent2) 27%, transparent);
  color: var(--accent2);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: var(--s6) 0;
}

/* Task 12.2: Enhanced Empty State */
.empty-state {
  text-align: center;
  padding: var(--s12);
  color: var(--muted);
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s6);
  min-height: 200px;
}

.empty-state-icon {
  font-size: 2.5rem;
  opacity: 0.5;
  line-height: 1;
}

.empty-state-text {
  font-size: var(--s8);
  line-height: 1.5;
  max-width: 300px;
}

.empty-state-action {
  margin-top: var(--s4);
}

/* FORM VALIDATION */
.field-group {
  position: relative;
  margin-bottom: var(--s6);
}

.input-error,
input.input-error,
select.input-error,
textarea.input-error {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 5%, var(--surface));
}

.input-error:focus {
  outline-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 15%, transparent);
}

.form-error-message {
  font-size: 0.7rem;
  color: var(--danger);
  margin-top: var(--s3);
  padding-left: var(--s2);
  display: none;
  line-height: 1.3;
}

.form-error-message.visible {
  display: block;
}

.form-error-icon {
  display: inline-block;
  margin-right: var(--s2);
}

input[aria-invalid='true'],
select[aria-invalid='true'],
textarea[aria-invalid='true'] {
  border-color: var(--danger);
}

/* KEYBOARD FOCUS INDICATORS */
*:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

/* SOURCE / EDIT */
.item-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--s8) var(--s9);
  margin-bottom: var(--s6);
}

.item-row:last-child {
  margin-bottom: 0;
}

.item-header {
  display: flex;
  align-items: center;
  gap: var(--s6);
  flex-wrap: wrap;
}

.item-name {
  font-weight: 700;
  font-size: 0.85rem;
  flex: 1;
}

.item-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: var(--s2);
}

.item-actions {
  display: flex;
  gap: var(--s3);
  align-items: center;
  flex-shrink: 0;
}

.edit-form {
  background: transparent;
  border-radius: var(--radius-sm);
  padding: var(--s8) 0;
  margin-top: var(--s6);
  display: none;
}

.edit-form.open {
  display: block;
}

/* PAY CHIPS */
.pay-strip {
  display: flex;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-top: var(--s4);
}

.pay-chip {
  font-size: 0.63rem;
  padding: var(--s2) var(--s5);
  border-radius: var(--radius-sm-md);
  font-weight: 700;
  white-space: nowrap;
}

.pay-chip.cur {
  background: color-mix(in srgb, var(--accent2) 13%, transparent); /* Issue #281 */
  color: var(--accent2);
  border: 1px solid color-mix(in srgb, var(--accent2) 27%, transparent);
}

.pay-chip.fut {
  background: color-mix(in srgb, var(--accent2) 7%, transparent); /* Issue #281 */
  color: var(--accent2);
  border: 1px solid color-mix(in srgb, var(--accent2) 20%, transparent);
}

.pay-chip.p5 {
  background: color-mix(in srgb, var(--warn) 13%, transparent); /* Issue #281 */
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 27%, transparent);
}

/* MONTH BANNER */
.month-banner {
  background: linear-gradient(
    135deg,
    var(--accent2-bg-subtle),
    color-mix(in srgb, #38f9d7 7%, transparent)
  );
  border: 1px solid var(--accent2-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--s7) var(--s9);
  margin-top: var(--s7);
}

.month-banner-title {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: var(--tracking-lg);
  color: var(--muted);
  font-weight: 700;
  margin-bottom: var(--s3);
}

.mb-row {
  display: flex;
  gap: var(--s10);
  flex-wrap: wrap;
  align-items: baseline;
}

.mb-val {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}

.mb-avg {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent2);
}

.mb-sub {
  font-size: 0.64rem;
  color: var(--muted);
  margin-top: var(--s1);
}

/* BAR CHART */
.bar-chart {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

.bar-row {
  display: flex;
  align-items: center;
  gap: var(--s5);
}

.bar-label {
  width: 46px;
  text-align: right;
  color: var(--muted);
  flex-shrink: 0;
  font-size: 0.67rem;
}

.bar-outer {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius-pill);
  height: 19px;
  overflow: hidden;
  min-width: 0;
}

.bar-inner {
  height: 100%;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  padding-left: var(--s3);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text); /* Issue #281: Use design token instead of hardcoded #fff */
  white-space: nowrap;
  min-width: 4px;
  transition: width 0.5s;
}

.bar-val {
  width: 72px;
  color: var(--accent2);
  font-weight: 700;
  text-align: right;
  font-size: 0.69rem;
  flex-shrink: 0;
}

/* EMOJI PICKER */
.emoji-cat-btn {
  background: none;
  border: none;
  padding: var(--s3) var(--s4);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.05rem;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.emoji-cat-btn:hover {
  background: var(--surface);
}

.emoji-cat-btn.active {
  background: var(--border);
}

.emoji-cell {
  background: none;
  border: none;
  font-size: 1.35rem;
  padding: var(--s2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.emoji-cell:hover {
  background: var(--surface);
}

.emoji-cell:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--shadow-heavy);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s10);
}

.modal-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s12);
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 40px var(--shadow-dark);
  animation: modal-in 0.15s ease;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-msg {
  font-size: 0.85rem;
  line-height: var(--lh);
  margin-bottom: var(--s10);
  color: var(--text);
}

.modal-btns {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Task 12.5: Installation Progress UI */
.install-progress {
  display: flex;
  flex-direction: column;
  gap: var(--s10);
}

.install-step {
  display: flex;
  align-items: center;
  gap: var(--s7);
  font-size: 0.85rem;
  color: var(--muted);
  padding: var(--s5) 0;
}

.install-step.active {
  color: var(--accent2);
  font-weight: 600;
}

.install-step.complete {
  color: var(--text);
}

.install-step.error {
  color: var(--danger);
}

.install-step::before {
  content: '○';
  font-size: 1.2rem;
  width: 1.5rem;
  text-align: center;
}

.install-step.active::before {
  content: '◉';
  color: var(--accent2);
}

.install-step.complete::before {
  content: '✓';
  color: var(--accent2);
}

.install-step.error::before {
  content: '✗';
  color: var(--danger);
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-top: var(--s5);
}

.progress-fill {
  height: 100%;
  background: var(--accent2);
  border-radius: var(--radius-pill);
  transition: width 0.3s ease;
  animation: progress-pulse 1.5s ease-in-out infinite;
}

.progress-fill.complete {
  animation: none;
}

@keyframes progress-pulse {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }

  100% {
    opacity: 1;
  }
}

/* TOOLS APP GRID */
.tools-app-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s12);
  padding: var(--s6);
}

@media (width >= 480px) {
  .tools-app-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.tool-app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  border: none;
  background: none;
}

.tool-app-item:focus-visible .tool-app-icon-bg {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

.tool-app-item:active .tool-app-icon-bg {
  transform: scale(0.9);
}

.tool-app-icon-bg {
  width: 62px;
  height: 62px;
  border-radius: var(--radius-icon);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px var(--shadow-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease;
}

.tool-app-icon-bg:hover {
  box-shadow: 0 4px 14px var(--shadow-strong);
}

.tool-app-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  max-width: 80px;
  line-height: 1.25;
  word-break: break-word;
}

.tool-app-item--card {
  cursor: default;
}

.tool-app-item--card:active .tool-app-icon-bg {
  transform: none;
}

/* Tools view toggle */
.tools-view-toggle {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
}

.tvt-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--muted);
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  max-width: 36px;
  max-height: 36px;
  aspect-ratio: 1;
  flex-shrink: 0;
  align-self: center;
  box-sizing: border-box;
}

.tvt-btn.active {
  background: var(--accent2);
  color: var(--on-accent);
  border-color: var(--accent2);
  font-weight: 700;
}

/* Tools grid — 4-col mode */
.tools-app-grid.grid4 {
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s8);
}

.tools-app-grid.grid4 .tool-app-icon-bg {
  width: 62px;
  height: 62px;
  font-size: 1.8rem;
}

.tools-app-grid.grid4 .tool-app-label {
  font-size: 0.65rem;
  max-width: 70px;
}

/* Tools list view (App Store style) */
.tools-list-view {
  display: flex;
  flex-direction: column;
  gap: var(--s7);
}

.tools-list-item {
  display: flex;
  align-items: center;
  gap: var(--s9);
  padding: var(--s8) var(--s9);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity var(--transition-fast);
}

.tools-list-item:active {
  opacity: 0.75;
}

.tools-list-item--actions {
  cursor: default;
}

.tools-list-item--actions:active {
  opacity: 1;
}

.tools-list-icon {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.55rem;
  flex-shrink: 0;
  box-shadow: 0 1px 4px var(--shadow-light);
}

.tools-list-info {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.tools-list-name {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text);
}

.tools-list-desc {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: var(--s2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tools-list-chevron {
  font-size: 1.1rem;
  color: var(--muted);
  flex-shrink: 0;
  padding-left: var(--s5);
}

.tools-list-actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

/* SWIPE ACTIONS (swipe actions) */
.swipe-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  margin-bottom: var(--s8);
  transform: translateZ(0);
}

.swipe-bg {
  position: absolute;
  top: 0;
  height: 100%;
  width: var(--swipe-width);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
}

.swipe-bg-edit {
  right: 0;
  background: var(--accent2);
  color: var(--on-accent);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

.swipe-bg-del {
  left: 0;
  background: var(--danger);
  color: var(--on-danger);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.swipe-card {
  position: relative;
  background: var(--card);
  z-index: 2;
  touch-action: pan-x;
  overscroll-behavior-x: none;
}

.swipe-card.swipe-transitioning {
  transition: transform var(--transition-slow) ease-out;
}

/* FORM POPUP OVERLAY */
.form-popup-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-modal);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s10);
}

.form-popup-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  padding: var(--s11);
  max-height: 88vh;
  overflow-y: auto;
  scrollbar-width: none;
}

.form-popup-box::-webkit-scrollbar {
  display: none;
}

.form-popup-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.form-popup-hdr span {
  font-weight: 700;
  font-size: 0.95rem;
}

.form-popup-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  padding: var(--s1) var(--s4);
  line-height: 1;
}

/* ACCESSIBILITY */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button.as-div {
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  width: 100%;
  font: inherit;
  color: inherit;
}

button.as-div:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

/* UTILITY CLASSES */
.row {
  display: flex;
  align-items: center;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.row-wrap {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.col {
  display: flex;
  flex-direction: column;
}

.gap-sm {
  gap: var(--s4);
}

.gap-md {
  gap: var(--s7);
}

.text-muted {
  color: var(--muted);
}

.text-danger {
  color: var(--danger);
}

.text-sm {
  font-size: var(--s7);
}

.text-xs {
  font-size: var(--s6);
}

.fw-bold {
  font-weight: 700;
}

.fw-semibold {
  font-weight: 600;
}

.mb-1 {
  margin-bottom: var(--s5);
}

.mb-2 {
  margin-bottom: var(--s7);
}

.mb-3 {
  margin-bottom: var(--s9);
}

.mt-1 {
  margin-top: var(--s5);
}

/* PAY CHIPS (tokenized) */
.pay-chip--today {
  background: var(--accent2);
  border-color: var(--accent2);
}

.pay-chip--next {
  background: color-mix(in srgb, var(--accent2) 12%, transparent);
  border-color: color-mix(in srgb, var(--accent2) 35%, transparent);
}

/* ═════════════════════════════════════════════════════════════════════════
   SETTINGS MODULE v2.0 - Phase 2
   ═════════════════════════════════════════════════════════════════════════ */

/* Settings Page Container */
.page-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  height: var(--nav-height);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--s9);
  box-shadow: 0 2px 12px #0005;
}

.top-nav-title {
  font-size: var(--s10);
  font-weight: 700;
  letter-spacing: var(--tracking-sm);
}

.back-btn {
  position: absolute;
  left: var(--s9);
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: var(--s3);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.back-btn:hover {
  background: var(--surface);
}

.content-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: var(--s9);
  padding-bottom: calc(var(--s12) + var(--nav-height) + env(safe-area-inset-bottom, 0px));
}

/* Settings Home - Category Grid */
.settings-home {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s9);
}

/* Settings Category Card */
.settings-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s7) var(--s9);
  cursor: pointer;
  transition:
    transform 0.15s,
    box-shadow 0.15s;
  position: relative;
  display: flex;
  flex-direction: row;
  gap: var(--s9);
  min-height: 68px;
  -webkit-tap-highlight-color: transparent;
  align-items: center;
}

/* Issue #269: Use CSS :active instead of JS-managed .is-pressed class to avoid memory leaks */
.settings-card.is-pressed,
.settings-card:active {
  transform: scale(0.97);
  box-shadow: 0 4px 16px var(--shadow-card);
}

@media (hover: hover) {
  .settings-card:hover {
    box-shadow: 0 4px 16px var(--shadow-card);
  }
}

.settings-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--accent2);
}

.settings-card-icon svg {
  width: var(--icon-lg);
  height: var(--icon-lg);
  stroke: currentcolor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings-card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.settings-card-title {
  font-weight: 700;
  font-size: var(--s9);
  color: var(--text);
}

.settings-card-desc {
  font-size: var(--s6);
  color: var(--muted);
  line-height: 1.3;
  margin-top: var(--s2);
}

.settings-card-arrow {
  position: absolute;
  top: 50%;
  right: var(--s8);
  transform: translateY(-50%);
  color: var(--muted);
  font-size: var(--s11);
  font-weight: 300;
}

/* Settings Section Pages */
.settings-section {
  max-width: 600px;
  margin: 0 auto;
}

.settings-section h3 {
  font-size: var(--s11);
  font-weight: 700;
  margin-bottom: var(--s9);
  color: var(--text);
}

.settings-section-desc {
  font-size: var(--s8);
  color: var(--muted);
  margin-bottom: var(--s10);
  line-height: 1.5;
}

/* Settings Groups */
.settings-group {
  margin-bottom: var(--s12);
}

.settings-group-title {
  font-size: var(--s9);
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--s8);
  padding-bottom: var(--s5);
  border-bottom: 1px solid var(--border);
}

.settings-group-body {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--s8) var(--s9);
}

/* Themes Grid */
.themes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s9);
}

@media (width >= 390px) {
  .themes-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.theme-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--s8);
  cursor: pointer;
  transition:
    transform 0.15s,
    border-color 0.15s;
  position: relative;
}

.theme-card:hover {
  border-color: var(--accent2);
  transform: scale(1.02);
}

.theme-card-active {
  border-color: var(--accent2);
  background: color-mix(in srgb, var(--accent2) 10%, var(--surface));
}

.theme-card-preview {
  width: 100%;
  aspect-ratio: 3/2;
  background: linear-gradient(135deg, var(--bg), var(--card));
  border-radius: var(--radius-sm);
  margin-bottom: var(--s6);
  position: relative;
  overflow: hidden;
}

.theme-card-checkmark {
  position: absolute;
  top: var(--s4);
  right: var(--s4);
  background: var(--accent2);
  color: var(--on-accent);
  width: 24px;
  height: 24px;
  border-radius: var(--radius-circle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
}

.theme-card-name {
  font-size: var(--s8);
  font-weight: 600;
  text-align: center;
  color: var(--text);
}

/* ═══ DASHBOARD WIDGET GRID ═══ */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s8);
  padding: var(--s7);
  padding-bottom: calc(var(--s12) + var(--nav-height) + env(safe-area-inset-bottom, 0px));
  max-width: var(--content-max-w);
  margin: 0 auto;
  touch-action: pan-y;
  overscroll-behavior-x: none;
  container-type: inline-size;
  container-name: widget-grid;
}

/* Issue #23: Prevent horizontal swipe conflicts during widget drag */

/* Edit Mode State - Grid & Widgets */
.widget-grid.edit-mode {
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  position: relative;
}

/* Container query: widget sizing adapts to grid container width */
@container widget-grid (max-width: 300px) {
  .widget-size-standard,
  .widget-size-half,
  .widget-size-expanded {
    grid-column: span 3;
  }

  .widget-size-compact,
  .widget-size-small {
    grid-column: span 3;
  }
}

/* Widget Slot */
.widget-slot {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition:
    opacity 0.2s,
    transform 0.15s;
  position: relative;
  display: flex;
  flex-direction: column;
}

.widget-slot-dragging {
  opacity: 0.5;
  transform: scale(0.98);
}

.widget-slot-dragover {
  border-color: var(--accent2);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent2) 20%, transparent);
}

/* Widget Slot Header — hidden by default, shown only in edit mode */
.widget-slot-header {
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--s5) var(--s7);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  min-height: 38px;
  cursor: grab;
  user-select: none;
}

.widget-slot-header:active {
  cursor: grabbing;
}

.widget-slot-title {
  display: flex;
  align-items: center;
  gap: var(--s5);
  font-size: var(--s8);
  font-weight: 700;
  color: var(--text);
}

.widget-slot-icon {
  font-size: var(--s10);
  line-height: 1;
}

.widget-slot-actions {
  display: flex;
  align-items: center;
  gap: var(--s4);
}

.widget-slot-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: var(--s2);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition:
    background 0.15s,
    color 0.15s;
}

.widget-slot-btn:hover {
  background: var(--card);
  color: var(--text);
}

.widget-slot-btn svg {
  width: var(--icon-sm);
  height: var(--icon-sm);
  stroke: currentcolor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Widget Slot Content */
.widget-slot-content {
  flex: 1;
  padding: var(--s4);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 140px;
}

/* Widget Sizes — classes applied as widget-size-{size} by widget host
   Grid is 3-column (.widget-grid), so half spans 2 and expanded spans 3 */
.widget-size-compact {
  aspect-ratio: 1;
  grid-column: span 1;
}

.widget-size-compact .widget-slot-content {
  padding: var(--s5);
  align-items: center;
  justify-content: center;
  min-height: 90px;
}

.widget-size-standard {
  aspect-ratio: 2/1;
  grid-column: span 2;
}

.widget-size-standard .widget-slot-content {
  padding: var(--s6) var(--s7);
  align-items: center;
  justify-content: center;
  min-height: 130px;
}

.widget-size-half {
  grid-column: span 2;
}

.widget-size-expanded {
  grid-column: span 3;
}

.widget-size-half .widget-slot-content,
.widget-size-expanded .widget-slot-content {
  padding: var(--s7) var(--s8);
  min-height: 180px;
}

/* Task 12.2: Enhanced Widget Loading State */
.widget-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s12);
  color: var(--muted);
  gap: var(--s6);
  min-height: 120px;
}

.widget-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: widget-spin 0.8s linear infinite;
  will-change: transform;
}

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

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

.widget-loading-text {
  font-size: var(--s7);
  color: var(--muted);
  font-weight: 500;
}

/* Task 12.2: Enhanced Widget Error State */
.widget-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s9);
  text-align: center;
  color: var(--danger);
  gap: var(--s5);
  min-height: 120px;
  background: color-mix(in srgb, var(--danger) 3%, transparent);
  border-radius: var(--radius-sm);
}

.widget-error-icon {
  font-size: 2rem;
  line-height: 1;
  opacity: 0.8;
}

.widget-error-text {
  font-size: var(--s7);
  line-height: 1.4;
  color: var(--text);
  font-weight: 500;
}

.widget-error-retry {
  margin-top: var(--s4);
}

/* Task 12.2: Generic Error State (for non-widget errors) */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s12);
  text-align: center;
  gap: var(--s6);
  min-height: 200px;
  background: color-mix(in srgb, var(--danger) 3%, transparent);
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--danger) 20%, transparent);
}

.error-state-icon {
  font-size: 2.5rem;
  color: var(--danger);
  opacity: 0.7;
  line-height: 1;
}

.error-state-title {
  font-size: var(--s10);
  font-weight: 600;
  color: var(--text);
}

.error-state-message {
  font-size: var(--s8);
  color: var(--muted);
  line-height: 1.5;
  max-width: 350px;
}

.error-state-action {
  margin-top: var(--s4);
}

/* ── Phase 5: Edit Mode & Drag-and-Drop ─────────────── */

/* Edit Mode Banner — floating Done button above bottom nav */
.edit-mode-banner {
  position: fixed;
  bottom: calc(var(--nav-height) + 0.67rem + env(safe-area-inset-bottom, 0px));
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--accent2);
  color: white;
  padding: var(--s9) var(--s9); /* Phase 3 Issue 10: Increased from var(--s6) */
  text-align: center;
  font-size: var(--s8);
  font-weight: 700;
  box-shadow: 0 -2px 12px var(--shadow-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s7);
}

/* Phase 3 Issue 10: Widget selection display in banner */
.edit-mode-widget-selected {
  display: flex;
  align-items: center;
  gap: var(--s6);
  flex: 1;
  min-width: 0;
}

.edit-mode-widget-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.edit-mode-size-btns {
  display: flex;
  gap: var(--s3);
}

.edit-mode-size-btn {
  background: var(--white-overlay-light);
  border: 1px solid var(--white-overlay-strong);
  color: white;
  padding: var(--s3) var(--s6);
  border-radius: var(--radius-sm);
  font-size: var(--s7);
  cursor: pointer;
  transition:
    background var(--transition-base),
    color var(--transition-base);
}

.edit-mode-size-btn:hover {
  background: var(--white-overlay-medium);
}

.edit-mode-size-btn.active {
  background: white;
  color: var(--accent2);
  font-weight: 700;
}

.edit-mode-settings-btn {
  background: var(--white-overlay-light);
  border: 1px solid var(--white-overlay-strong);
  color: white;
  padding: var(--s5) var(--s7);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--s8);
  font-weight: 600;
  transition: background var(--transition-base);
  white-space: nowrap;
}

.edit-mode-settings-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.edit-mode-done-btn {
  background: white;
  color: var(--accent2);
  border: none;
  padding: var(--s5) var(--s8);
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  transition: opacity var(--transition-base);
  white-space: nowrap;
}

.edit-mode-done-btn:hover {
  opacity: 0.9;
}

/* Edit Mode FAB (Floating Action Button) */

/* edit-mode-fab removed — edit button is now inline .tvt-btn in dashboard header */

.widget-grid.edit-mode .widget-slot {
  border: 2px dashed var(--border);
  cursor: grab;
}

.widget-grid.edit-mode .widget-slot:active {
  cursor: grabbing;
}

.widget-grid.edit-mode .widget-slot-header {
  display: flex !important;
  background: color-mix(in srgb, var(--accent2) 10%, var(--surface));
  cursor: grab;
}

/* Grid Overlay - shown during drag */
.widget-grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent calc(33.33% - 1px),
      var(--border) calc(33.33% - 1px),
      var(--border) 33.33%
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent calc(33.33% - 1px),
      var(--border) calc(33.33% - 1px),
      var(--border) 33.33%
    );
  opacity: 0.3;
  z-index: 100;
}

.widget-grid.edit-mode.dragging .widget-grid-overlay {
  display: block;
}

/* Ghost Element During Drag */
.widget-slot-ghost {
  box-shadow: 0 8px 24px var(--shadow-card);
  transition: none !important;
  pointer-events: none;
}

/* stylelint-disable-next-line comment-empty-line-before -- Keep comment with related code */
/* stylelint-disable no-duplicate-selectors -- Widget drag states refined with more specific values */

/* Original Slot While Dragging */
.widget-slot-dragging {
  opacity: 0.3;
  transform: scale(0.95);
}

/* Valid Drop Target */
.widget-slot-dragover {
  border-color: var(--accent2);
  border-style: solid;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent2) 20%, transparent);
  transform: scale(1.02);
  background: color-mix(in srgb, var(--accent2) 5%, var(--card));
}

/* Insertion Point Indicator (Issue #6) */
.widget-slot-dragover::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent2);
  border-radius: var(--radius-pill);
  animation: pulse-indicator 0.6s ease-in-out infinite;
  z-index: 1000;
}

@keyframes pulse-indicator {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

/* Disable Text Selection During Drag */
.widget-grid.edit-mode * {
  -webkit-tap-highlight-color: transparent;
}

/* ── Widget Slot additional transitions (Phase 7.1) ────────────────────── */
.widget-slot {
  transition:
    border-color 0.2s,
    box-shadow 0.2s,
    transform 0.2s,
    opacity 0.2s;
}

.widget-slot-title {
  display: flex;
  align-items: center;
  gap: var(--s5);
  flex: 1;
  min-width: 0;
}

.widget-icon {
  font-size: var(--s12);
  flex-shrink: 0;
}

.widget-name {
  font-weight: 700;
  font-size: var(--s8);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-lock-icon {
  font-size: var(--s8);
  color: var(--muted);
  margin-left: var(--s4);
}

/* Widget Slot Actions */
.widget-slot-actions {
  display: flex;
  align-items: center;
  gap: var(--s4);
  flex-shrink: 0;
}

.widget-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: var(--s4);
  border-radius: var(--radius-sm);
  min-width: 32px;
  min-height: 32px;
  transition:
    background 0.15s,
    color 0.15s;
}

.widget-action-btn:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
  color: var(--text);
}

.widget-action-btn:active {
  transform: scale(0.95);
}

/* Widget Size Selector (Phase 7.1) */
.widget-size-selector {
  display: flex;
  gap: var(--s2);
  background: color-mix(in srgb, var(--border) 30%, transparent);
  border-radius: var(--radius-sm);
  padding: var(--s2);
}

.widget-size-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: var(--s3) var(--s6);
  border-radius: var(--radius-sm);
  font-size: var(--s7);
  font-weight: 700;
  min-width: 36px;
  min-height: 36px;
  transition:
    background 0.15s,
    color 0.15s;
}

.widget-size-btn:hover {
  background: color-mix(in srgb, var(--text) 10%, transparent);
}

.widget-size-btn:active {
  transform: scale(0.95);
}

/* Widget Size Variants — compact/small = half-width (1 col), others = full-width (2 col) */
.widget-size-small {
  min-height: var(--widget-min-sm);
  grid-column: span 1;
}

.widget-size-compact {
  min-height: var(--widget-min-compact);
  grid-column: span 1;
}

.widget-size-standard {
  min-height: var(--widget-min-standard);
  grid-column: span 2;
}

.widget-size-half {
  min-height: var(--widget-min-standard);
  grid-column: span 2;
}

.widget-size-expanded {
  min-height: var(--widget-min-expanded);
  grid-column: span 2;
}
/* stylelint-enable no-duplicate-selectors */

/* Lock Icon (Edit Mode Only) */
.widget-lock-btn {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: var(--s4);
  border-radius: var(--radius-sm);
  transition:
    background 0.15s,
    color 0.15s;
}

.widget-lock-btn:hover {
  background: var(--surface);
  color: var(--text);
}

.widget-lock-btn.locked {
  color: var(--warn);
}

/* Resize Buttons (Edit Mode Only) */
.widget-resize-handles {
  display: none;
  padding: var(--s5) var(--s8);
  border-top: 1px solid var(--border);
  background: var(--surface);
  gap: var(--s4);
  justify-content: center;
}

.widget-grid.edit-mode .widget-resize-handles {
  display: flex;
}

.widget-resize-btn {
  min-width: 44px;
  min-height: 36px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  font-size: var(--s7);
  font-weight: 700;
  transition:
    background 0.15s,
    border-color 0.15s;
  padding: 0 var(--s6);
}

.widget-resize-btn:hover {
  background: var(--surface);
  border-color: var(--accent2);
}

.widget-resize-btn.active {
  background: var(--accent2);
  color: white;
  border-color: var(--accent2);
}

/* ── Widget Config Modal (Phase 7.2) ───────────────────── */
#widget-config-form {
  font-size: var(--s8);
}

#widget-config-form input[type='text'],
#widget-config-form input[type='password'],
#widget-config-form input[type='number'],
#widget-config-form select,
#widget-config-form textarea {
  width: 100%;
  padding: var(--s6) var(--s7);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--s8);
  margin-top: var(--s3);
}

#widget-config-form input:focus,
#widget-config-form select:focus,
#widget-config-form textarea:focus {
  outline: none;
  border-color: var(--accent2);
}

#widget-config-form label {
  display: block;
  margin-bottom: var(--s6);
  font-weight: 600;
  color: var(--text);
}

#widget-config-form .btn {
  margin-top: var(--s8);
}

/* ── Module Search (QW-3) ─────────────────────────────── */
/* stylelint-disable-next-line selector-id-pattern -- Legacy ID from DOM */
#moduleSearchInput:focus {
  outline: none;
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent2) 15%, transparent);
}

/* iOS-Specific Touch Handling */
@supports (-webkit-touch-callout: none) {
  .widget-grid.edit-mode {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }

  .widget-slot-header {
    user-select: none;
  }
}

/* ═══ APP STORE ═══ */

/* AppStore styles have been moved to modules/appstore/appstore.css */

/* The CSS is dynamically loaded when the AppStore module is enabled */

/* ═══════════════════════════════════════
   WIDGET SMALL SIZE
═══════════════════════════════════════ */
.widget-slot-small {
  min-height: 62px;
  max-height: 80px;
}

.widget-slot-small .widget-slot-content {
  padding: var(--s4);
  align-items: center;
  justify-content: center;
}

.widget-slot-half {
  min-height: 120px;
}

@media (width >= 480px) {
  .widget-slot-half {
    grid-column: span 1;
  }

  .as-screenshots {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (width >= 768px) {
  .as-screenshots {
    grid-template-columns: repeat(4, 1fr);
  }
}
