:root {
  --tmm-bg: #edf3fb;
  --tmm-paper: #ffffff;
  --tmm-panel: #fbfdff;
  --tmm-ink: #102033;
  --tmm-muted: #64748b;
  --tmm-faint: #94a3b8;
  --tmm-line: #d8e3f0;
  --tmm-blue: var(--hu-accent, #156ff7);
  --tmm-navy: var(--hu-navy, #071b3c);
  --tmm-green: #22c55e;
  --tmm-amber: #f59e0b;
  --tmm-red: #ef4444;
  --tmm-shadow: 0 2px 12px rgba(12, 30, 58, 0.08);
  --tmm-radius: 18px;
  --tmm-safe-top: env(safe-area-inset-top, 0px);
  --tmm-safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--tmm-bg);
  color: var(--tmm-ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

code {
  background: #eef5ff;
  color: #0b63df;
  border-radius: 6px;
  padding: 1px 5px;
}

.tmm-app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: calc(6px + var(--tmm-safe-bottom));
  background: linear-gradient(180deg, #f8fbff, var(--tmm-bg));
}

.tmm-topbar {
  padding: calc(8px + var(--tmm-safe-top)) 10px 8px;
  background: linear-gradient(180deg, var(--tmm-navy), #0b2854);
  color: white;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.16);
}

.tmm-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.tmm-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 6px;
  flex: 0 0 auto;
}

.tmm-logo span {
  background: white;
  border-radius: 2px;
}

.tmm-brand h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 950;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tmm-brand p {
  margin: 3px 0 0;
  color: #bdd2f0;
  font-size: 0.62rem;
  font-weight: 800;
}

.tmm-stats {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tmm-stat {
  min-width: 62px;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.13);
  background: rgba(255,255,255,0.08);
  border-radius: 11px;
  padding: 5px 7px;
}

.tmm-stat-label {
  display: block;
  font-size: 0.48rem;
  text-transform: uppercase;
  color: #bdd2f0;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.tmm-stat strong {
  display: block;
  font-size: 0.85rem;
  line-height: 1.1;
  margin-top: 2px;
}

.tmm-mobile-menu-btn {
  display: none;
  min-width: 38px;
  min-height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.1);
  color: white;
  font-weight: 950;
}

.tmm-tabs {
  display: flex;
  gap: 4px;
  padding: 0 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tmm-tabs::-webkit-scrollbar {
  display: none;
}

.tmm-tab {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--tmm-line);
  border-radius: 12px;
  background: white;
  color: #425873;
  font-size: 0.65rem;
  font-weight: 900;
  box-shadow: 0 2px 7px rgba(12,30,58,0.04);
  white-space: nowrap;
}

.tmm-tab.active {
  background: var(--tmm-blue);
  border-color: var(--tmm-blue);
  color: white;
}

.tmm-main {
  flex: 1;
  min-height: 0;
  padding: 0 6px;
  display: flex;
  flex-direction: column;
}

.tmm-panel {
  display: none;
  flex: 1;
  min-height: 0;
  background: var(--tmm-paper);
  border: 1px solid var(--tmm-line);
  border-radius: var(--tmm-radius);
  box-shadow: var(--tmm-shadow);
  overflow: auto;
  padding: 12px;
}

.tmm-panel.active {
  display: block;
}

.tmm-home-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
}

.tmm-hero-card,
.tmm-card,
.tmm-empty-state,
.tmm-side-panel,
.tmm-code-box {
  background: var(--tmm-panel);
  border: 1px solid var(--tmm-line);
  border-radius: 16px;
  padding: 14px;
}

.tmm-hero-card {
  grid-row: span 2;
  background: linear-gradient(135deg, #fef3c7, #fff7d6);
  border-color: #fcd34d;
}

.tmm-kicker {
  font-size: 0.62rem;
  text-transform: uppercase;
  font-weight: 950;
  letter-spacing: 0.08em;
  color: #9a6700;
  margin-bottom: 8px;
}

.tmm-hero-card h2 {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 5vw, 2.6rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.tmm-hero-card p,
.tmm-card p,
.tmm-empty-state {
  color: #52677f;
  font-size: 0.82rem;
  line-height: 1.45;
  font-weight: 750;
}

.tmm-hero-actions,
.tmm-panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.tmm-btn {
  min-height: 36px;
  border-radius: 12px;
  border: 1px solid var(--tmm-line);
  background: white;
  color: #405873;
  padding: 0 12px;
  font-size: 0.72rem;
  font-weight: 900;
  box-shadow: 0 2px 8px rgba(12,30,58,0.05);
}

.tmm-btn.primary {
  background: var(--tmm-blue);
  border-color: var(--tmm-blue);
  color: white;
}

.tmm-btn.small {
  min-height: 30px;
  border-radius: 10px;
  padding: 0 10px;
  font-size: 0.65rem;
}

.tmm-flow-list {
  margin: 8px 0 0;
  padding-left: 20px;
  color: #435a75;
  font-size: 0.78rem;
  line-height: 1.55;
  font-weight: 800;
}

.tmm-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.tmm-panel-header h2,
.tmm-card h3,
.tmm-side-panel h3 {
  margin: 0 0 4px;
  color: var(--tmm-ink);
}

.tmm-panel-header p {
  margin: 0;
  color: var(--tmm-muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.tmm-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) 330px;
  gap: 10px;
  min-height: 60dvh;
}

.tmm-canvas-shell {
  position: relative;
  min-height: 520px;
  background: #dbe5f2;
  border: 1px solid var(--tmm-line);
  border-radius: 16px;
  overflow: auto;
  display: grid;
  place-items: center;
}

#main-canvas,
#overlay-canvas {
  background: white;
  max-width: none;
  display: block;
}

#overlay-canvas {
  position: absolute;
  pointer-events: none;
}

.tmm-canvas-watermark {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--tmm-line);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--tmm-muted);
  font-size: 0.65rem;
  font-weight: 900;
}

.tmm-inspector-box {
  border: 1px solid var(--tmm-line);
  border-radius: 12px;
  background: white;
  padding: 10px;
  color: var(--tmm-muted);
  font-size: 0.75rem;
  font-weight: 800;
  min-height: 160px;
}

.tmm-grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.tmm-code-box {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  background: #0b1b33;
  color: #dbeafe;
  min-height: 240px;
  overflow: auto;
  font-size: 0.72rem;
}

.tmm-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.tmm-field {
  display: block;
  border: 1px solid var(--tmm-line);
  background: var(--tmm-panel);
  border-radius: 14px;
  padding: 9px;
}

.tmm-field span {
  display: block;
  font-size: 0.55rem;
  text-transform: uppercase;
  font-weight: 950;
  color: #718096;
  margin-bottom: 5px;
}

.tmm-field input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-size: 0.85rem;
  font-weight: 900;
  color: #183150;
}

.tmm-toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(14px + var(--tmm-safe-bottom));
  transform: translateX(-50%);
  z-index: 1000;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.tmm-toast {
  background: rgba(7, 27, 60, 0.94);
  color: white;
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 10px 35px rgba(0,0,0,0.25);
  font-size: 0.78rem;
  font-weight: 850;
  max-width: min(92vw, 520px);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.tmm-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.tmm-mobile-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(88vw, 360px);
  background: white;
  border-left: 1px solid var(--tmm-line);
  box-shadow: -20px 0 50px rgba(0,0,0,0.2);
  z-index: 900;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  padding: calc(12px + var(--tmm-safe-top)) 12px 12px;
}

.tmm-mobile-drawer.open {
  transform: translateX(0);
}

.tmm-mobile-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.tmm-mobile-drawer-tabs {
  display: grid;
  gap: 6px;
}

.tmm-mobile-drawer-tabs .tmm-tab {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

@media (min-width: 1100px) {
  .tmm-app {
    max-width: 1400px;
    margin: 0 auto;
    box-shadow: 0 0 0 1px var(--tmm-line);
  }
}

@media (max-width: 900px) {
  .tmm-topbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .tmm-stats {
    display: none;
  }

  .tmm-mobile-menu-btn {
    display: block;
  }

  .tmm-tabs {
    display: none;
  }

  .tmm-home-grid,
  .tmm-workspace {
    grid-template-columns: 1fr;
  }

  .tmm-canvas-shell {
    min-height: 360px;
  }

  .tmm-panel-header {
    flex-direction: column;
  }
}


/* ===== v34 Phase 3-8 merged module styles ===== */
.tmm-scanner-controls,
.tmm-perspective-controls,
.tmm-inventory-controls,
.tmm-calibration-actions,
.tmm-vein-controls,
.tmm-matching-controls,
.tmm-layout-actions,
.tmm-qrq-controls,
.tmm-pattern-controls,
.tmm-export-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  align-items: center;
}

.tmm-source-card,
.tmm-pattern-card {
  border: 1px solid var(--tmm-line);
  background: var(--tmm-panel);
  border-radius: 14px;
  overflow: hidden;
  padding: 0;
  text-align: left;
  color: var(--tmm-ink);
}

.tmm-source-card.active,
.tmm-tile-card.active {
  outline: 3px solid rgba(21,111,247,0.24);
  border-color: var(--tmm-blue);
}

.tmm-source-card img {
  display: block;
  width: 100%;
  height: 110px;
  object-fit: cover;
}

.tmm-source-card strong,
.tmm-source-card span,
.tmm-pattern-card strong,
.tmm-pattern-card span,
.tmm-pattern-card small {
  display: block;
  padding: 6px 8px 0;
  font-size: 0.72rem;
}

.tmm-source-card span,
.tmm-pattern-card span,
.tmm-pattern-card small {
  padding-bottom: 8px;
  color: var(--tmm-muted);
  font-size: 0.62rem;
  font-weight: 800;
}

.tmm-mini-field {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--tmm-line);
  background: white;
  border-radius: 12px;
  padding: 0 10px;
  color: var(--tmm-muted);
  font-size: 0.7rem;
  font-weight: 900;
}

.tmm-mini-field input {
  width: 58px;
  border: none;
  outline: none;
  font-weight: 900;
}

.tmm-tile-card {
  border: 1px solid var(--tmm-line);
  background: var(--tmm-panel);
  border-radius: 14px;
  overflow: hidden;
  padding-bottom: 8px;
}

.tmm-tile-thumb {
  height: 110px;
  background: #e5ebf3 center / cover no-repeat;
  border-bottom: 1px solid var(--tmm-line);
}

.tmm-tile-card strong,
.tmm-tile-card span,
.tmm-tile-card small {
  display: block;
  padding: 6px 8px 0;
}

.tmm-tile-card span,
.tmm-tile-card small {
  color: var(--tmm-muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.tmm-tile-select {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  color: inherit;
}

.tmm-tile-actions {
  display: flex;
  gap: 6px;
  padding: 8px;
}

.tmm-calibration-box {
  margin-top: 12px;
  border: 1px solid var(--tmm-line);
  background: var(--tmm-panel);
  border-radius: 16px;
  padding: 14px;
}

.tmm-matching-controls .tmm-code-box {
  flex-basis: 100%;
}

.tmm-layout-preview {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.tmm-layout-cell {
  min-height: 70px;
  border: 1px solid var(--tmm-line);
  background: var(--tmm-panel);
  border-radius: 12px;
  padding: 8px;
}

.tmm-layout-cell small,
.tmm-layout-cell span {
  display: block;
  color: var(--tmm-muted);
  font-size: 0.62rem;
  font-weight: 800;
}

.tmm-layout-cell strong {
  display: block;
  font-size: 0.9rem;
}

.tmm-star-canvas {
  display: block;
  width: 100%;
  max-width: 720px;
  height: auto;
  border-radius: 14px;
  border: 1px solid var(--tmm-line);
  margin-top: 12px;
}
