/* ============================================================
   Ditto Medical Web — Design System v3
   Font: Inter 4.1 (self-hosted)
   Primary: #b30c73 (magenta, del logo Ditto)
   Layout: dos paneles — sidebar izquierdo + panel principal
   ============================================================ */

/* ---- Inter — auto-hosted, no Google Fonts ---- */
@font-face {
  font-family: 'Inter';
  src: url('/static/fonts/Inter-Regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}

@font-face {
  font-family: 'Inter';
  src: url('/static/fonts/Inter-Medium.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('/static/fonts/Inter-SemiBold.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('/static/fonts/Inter-Bold.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('/static/fonts/Inter-ExtraBold.woff2') format('woff2');
  font-weight: 800; font-style: normal; font-display: swap;
}

/* ---- Francisco Serial Light — brand/display font ---- */
@font-face {
  font-family: 'Francisco Serial Light';
  src: url('/static/fonts/Francisco-Serial-Light.ttf') format('truetype');
  font-weight: 300; font-style: normal; font-display: swap;
}

.sf-light {
  font-family: 'Francisco Serial Light', 'Inter', system-ui, sans-serif !important;
  font-weight: 300 !important;
}

/* ---- Tokens ---- */
:root,
[data-theme="light"] {
  --dm-magenta:       #b30c73;
  --dm-magenta-dark:  #8a0a5a;
  --dm-magenta-light: #f8e8f2;
  --dm-magenta-mid:   #f0c8e0;

  --dm-bg:            #f7f7f8;
  --dm-surface:       #ffffff;
  --dm-border:        #e8e8ec;
  --dm-border-light:  #f0f0f3;

  --dm-text:          #111118;
  --dm-text-secondary:#52525b;
  --dm-text-muted:    #8b8b99;

  --dm-sidebar-bg:    #fafafa;
  --dm-sidebar-w:     300px;
  --dm-navbar-h:      52px;
  --dm-bottombar-h:   64px;

  /* PicoCSS overrides — must match its [data-theme=light] specificity */
  --pico-font-family:               'Inter', system-ui, -apple-system, sans-serif !important;
  --pico-primary:                   #b30c73 !important;
  --pico-primary-background:        #b30c73 !important;
  --pico-primary-border:            #b30c73 !important;
  --pico-primary-underline:         rgba(179,12,115,.35) !important;
  --pico-primary-hover:             #8a0a5a !important;
  --pico-primary-hover-background:  #8a0a5a !important;
  --pico-primary-hover-border:      #8a0a5a !important;
  --pico-primary-focus:             rgba(179,12,115,.22) !important;
  --pico-primary-inverse:           #ffffff !important;
  --pico-background-color:          #f7f7f8 !important;
  --pico-card-background-color:     #ffffff !important;
  --pico-form-element-active-border-color: #b30c73 !important;
  --pico-form-element-focus-color:         #b30c73 !important;
}

/* ---- Reset & base ---- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 17px;
  color: var(--dm-text);
  background: var(--dm-bg);
  -webkit-font-smoothing: antialiased;
}

/* ================================================================
   NAVBAR
   ================================================================ */
.site-header {
  height: var(--dm-navbar-h);
  background: var(--dm-surface);
  border-bottom: 1px solid var(--dm-border);
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 300;
  padding: 0 1rem;
  gap: 0;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none !important;
  flex-shrink: 0;
  margin-right: 1rem;
}

.nav-logo img {
  height: 28px;
  width: auto;
}

.nav-logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  font-family: 'Francisco Serial Light', 'Inter', system-ui, sans-serif;
  color: var(--dm-text) !important;
  letter-spacing: -0.01em;
  line-height: 1;
}

/* Mode tabs */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--dm-text-secondary) !important;
  text-decoration: none !important;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
  border: 1px solid transparent;
}

.nav-tab:hover {
  background: var(--dm-magenta-light);
  color: var(--dm-magenta) !important;
}

.nav-tab.active {
  background: var(--dm-magenta-light);
  color: var(--dm-magenta) !important;
  border-color: var(--dm-magenta-mid);
  font-weight: 600;
}

/* Nav actions (right side) */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  margin-left: auto;
  padding-left: 1rem;
}

.nav-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--dm-text-secondary) !important;
  background: transparent !important;
  border: 1px solid var(--dm-border) !important;
  cursor: pointer;
  text-decoration: none !important;
  transition: all 0.12s;
  line-height: 1.4;
}

.nav-action-btn:hover {
  border-color: var(--dm-magenta) !important;
  color: var(--dm-magenta) !important;
  background: var(--dm-magenta-light) !important;
}

.nav-action-btn.primary {
  background: var(--dm-magenta) !important;
  border-color: var(--dm-magenta) !important;
  color: #fff !important;
}

.nav-action-btn.primary:hover {
  background: var(--dm-magenta-dark) !important;
  border-color: var(--dm-magenta-dark) !important;
}

.nav-user-name {
  font-size: 0.75rem;
  color: var(--dm-text-muted);
  padding: 0 0.5rem;
}

/* ================================================================
   APP LAYOUT — sidebar + main panel
   ================================================================ */
.app-layout {
  display: flex;
  height: calc(100vh - var(--dm-navbar-h));
  overflow: hidden;
}

/* ---- Sidebar ---- */
.app-sidebar {
  width: var(--dm-sidebar-w);
  min-width: 240px;
  max-width: 360px;
  background: var(--dm-sidebar-bg);
  border-right: 1px solid var(--dm-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-section {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--dm-border-light);
}

.sidebar-section:last-child { border-bottom: none; }

.sidebar-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dm-text-muted);
  margin-bottom: 0.5rem;
  display: block;
}

.sidebar-select {
  width: 100%;
  padding: 0.45rem 0.65rem !important;
  font-size: 0.82rem !important;
  border: 1px solid var(--dm-border) !important;
  border-radius: 6px !important;
  background: var(--dm-surface) !important;
  color: var(--dm-text) !important;
  margin-bottom: 0 !important;
  cursor: pointer;
}

.sidebar-select:focus {
  border-color: var(--dm-magenta) !important;
  box-shadow: 0 0 0 3px rgba(179,12,115,.12) !important;
  outline: none;
}

/* Tool buttons in sidebar */
.tool-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--dm-text-secondary);
  background: transparent;
  border: 1px solid var(--dm-border);
  cursor: pointer;
  margin-bottom: 0.3rem;
  text-align: left;
  transition: all 0.12s;
}

.tool-btn:hover {
  background: var(--dm-magenta-light);
  border-color: var(--dm-magenta-mid);
  color: var(--dm-magenta);
}

.tool-btn img { width: 14px; height: 14px; opacity: 0.6; }

/* Transcription area */
.transcript-box {
  background: var(--dm-surface);
  border: 1px solid var(--dm-border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--dm-text-secondary);
  flex: 1;
  min-height: 80px;
  min-height: 0; /* allow shrink below content in flex */
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Main panel ---- */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--dm-surface);
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--dm-border);
  background: var(--dm-surface);
  flex-shrink: 0;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.main-header-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--dm-text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.main-header-meta {
  font-size: 0.75rem;
  color: var(--dm-text-muted);
  font-weight: 400;
}

.main-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

/* ---- Bottom bar ---- */
.app-bottom-bar {
  min-height: var(--dm-bottombar-h);
  height: auto;
  background: var(--dm-surface);
  border-top: 1px solid var(--dm-border);
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  flex-shrink: 0;
}

@media (max-width: 767px) {
  .app-bottom-bar {
    padding: 0.6rem 0.75rem;
  }
  .app-bottom-bar .bottom-textarea {
    width: 100%;
    flex: none;
    order: 1;
  }
  .app-bottom-bar .bottom-bar-actions {
    width: 100%;
    flex: none;
    order: 2;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
  }
}

/* textarea expandible — reemplaza bottom-input */
.bottom-textarea {
  flex: 1;
  padding: 0.5rem 0.875rem !important;
  font-size: 0.85rem !important;
  font-family: 'Inter', system-ui, sans-serif !important;
  border: 1px solid var(--dm-border) !important;
  border-radius: 8px !important;
  background: var(--dm-bg) !important;
  color: var(--dm-text) !important;
  margin: 0 !important;
  resize: none;
  overflow-y: hidden;
  line-height: 1.5;
  min-height: 38px;
  max-height: calc(6 * 1.5em + 1rem);
  transition: border-color .15s, box-shadow .15s;
}

.bottom-textarea:focus {
  border-color: var(--dm-magenta) !important;
  box-shadow: 0 0 0 3px rgba(179,12,115,.12) !important;
  outline: none;
  background: var(--dm-surface) !important;
}

/* keep bottom-input for legacy use */
.bottom-input {
  flex: 1;
  padding: 0.5rem 0.875rem !important;
  font-size: 0.85rem !important;
  border: 1px solid var(--dm-border) !important;
  border-radius: 8px !important;
  background: var(--dm-bg) !important;
  color: var(--dm-text) !important;
  margin: 0 !important;
  transition: border-color .15s, box-shadow .15s;
}

.bottom-input:focus {
  border-color: var(--dm-magenta) !important;
  box-shadow: 0 0 0 3px rgba(179,12,115,.12) !important;
  outline: none;
  background: var(--dm-surface) !important;
}

.bottom-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.875rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid var(--dm-border);
  background: var(--dm-surface);
  color: var(--dm-text);
  transition: all 0.12s;
  line-height: 1;
}

.bottom-btn:hover {
  border-color: var(--dm-magenta);
  color: var(--dm-magenta);
  background: var(--dm-magenta-light);
}

.bottom-btn.primary {
  background: var(--dm-magenta) !important;
  border-color: var(--dm-magenta) !important;
  color: #fff !important;
}

.bottom-btn.primary:hover {
  background: var(--dm-magenta-dark) !important;
  border-color: var(--dm-magenta-dark) !important;
}

.bottom-btn.record-btn {
  background: var(--dm-magenta) !important;
  border-color: var(--dm-magenta) !important;
  color: #fff !important;
  min-width: 90px;
  justify-content: center;
}

.bottom-btn.record-btn.recording {
  background: #dc2626 !important;
  border-color: #dc2626 !important;
  animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
  0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.4); }
  50%      { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
}

.recording-timer {
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #dc2626;
  min-width: 44px;
  text-align: center;
}

/* ================================================================
   FIELD CARDS (detail/result page)
   ================================================================ */
.field-card {
  background: var(--dm-surface);
  border: 1px solid var(--dm-border);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  margin-bottom: 0.6rem;
  transition: border-color .15s, box-shadow .15s;
}

.field-card:focus-within {
  border-color: var(--dm-magenta);
  box-shadow: 0 0 0 3px rgba(179,12,115,.1);
}

.field-card.readonly { background: var(--dm-bg); }

.field-card label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dm-text-muted);
  margin-bottom: 0.35rem;
}

.field-card input[type="text"],
.field-card textarea {
  width: 100%;
  margin: 0 !important;
  border: 1px solid transparent !important;
  background: transparent;
  font-size: 0.875rem !important;
  color: var(--dm-text) !important;
  padding: 0.25rem 0 !important;
  resize: vertical;
}

.field-card input[type="text"]:focus,
.field-card textarea:focus {
  border-color: transparent !important;
  box-shadow: none !important;
  outline: none;
}

.field-card.readonly input,
.field-card.readonly textarea {
  cursor: default;
  color: var(--dm-text-secondary) !important;
}

/* ================================================================
   STATUS BADGES
   ================================================================ */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.18em 0.6em;
  border-radius: 20px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.status-draft {
  background: #fff8e1;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.status-finalized {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #86efac;
}

.badge-default {
  background: var(--dm-magenta-light);
  color: var(--dm-magenta-dark);
  border: 1px solid var(--dm-magenta-mid);
}

.badge-custom {
  background: #faf5ff;
  color: #6b21a8;
  border: 1px solid #d8b4fe;
}

/* ================================================================
   STANDARD PAGE LAYOUT (non-two-panel pages)
   ================================================================ */
main.container {
  padding-top: 1.75rem;
  padding-bottom: 2.5rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-header hgroup { margin: 0; }
.page-header hgroup h2 { margin: 0; font-size: 1.2rem; font-weight: 700; color: var(--dm-text); }
.page-header hgroup p  { margin: 0; font-size: 0.8rem; color: var(--dm-text-muted); }

/* ================================================================
   TABLES
   ================================================================ */
table {
  width: 100%;
  background: var(--dm-surface);
  border: 1px solid var(--dm-border);
  border-radius: 8px;
  overflow: hidden;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  background: var(--dm-bg);
  color: var(--dm-text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--dm-border);
  text-align: left;
}

tbody tr { border-bottom: 1px solid var(--dm-border-light); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--dm-magenta-light); }
tbody td { padding: 0.75rem 1rem; vertical-align: middle; }
td a { color: var(--dm-magenta) !important; text-decoration: none; font-weight: 500; }
td a:hover { color: var(--dm-magenta-dark) !important; text-decoration: underline; }

/* ================================================================
   FILTER ROW
   ================================================================ */
.filter-row {
  display: flex;
  gap: 0.65rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  background: var(--dm-surface);
  border: 1px solid var(--dm-border);
  border-radius: 8px;
  padding: 0.875rem 1rem;
}

.filter-row label { margin-bottom: 0; font-size: 0.75rem; font-weight: 600; }
.filter-row input, .filter-row select { margin-bottom: 0 !important; min-width: 150px; font-size: 0.82rem !important; }
.filter-row .htmx-indicator { opacity: .5; font-size: 0.78rem; align-self: center; }

/* ================================================================
   META STRIP
   ================================================================ */
.meta-strip {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--dm-text-secondary);
  margin-bottom: 1.25rem;
  padding-bottom: 0.875rem;
  border-bottom: 1px solid var(--dm-border-light);
}

.meta-strip strong { color: var(--dm-text); font-weight: 600; }

/* ================================================================
   ACTION BAR
   ================================================================ */
.action-bar {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--dm-border);
}

.save-feedback { font-size: 0.8rem; color: #166534; min-height: 1.2em; }
.save-feedback.error { color: #991b1b; }

#spinner-save {
  width: 14px; height: 14px;
  border: 2px solid var(--dm-magenta);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: none;
}

/* ================================================================
   FLASH MESSAGES
   ================================================================ */
.flash-error {
  color: #991b1b; background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 6px; padding: 0.55rem 0.875rem;
  font-size: 0.82rem; margin: 0;
}

.flash-success {
  color: #166534; background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 6px; padding: 0.55rem 0.875rem;
  font-size: 0.82rem; margin: 0;
}

/* ================================================================
   BREADCRUMB
   ================================================================ */
nav[aria-label="Ruta"] { margin-bottom: 0.875rem; }
nav[aria-label="Ruta"] ul {
  display: flex; gap: 0; list-style: none; padding: 0; margin: 0;
  font-size: 0.78rem; color: var(--dm-text-muted); align-items: center;
}
nav[aria-label="Ruta"] ul li { display: flex; align-items: center; }
nav[aria-label="Ruta"] ul li:not(:last-child)::after { content: "/"; margin: 0 .4rem; color: var(--dm-border); }
nav[aria-label="Ruta"] ul a { color: var(--dm-magenta) !important; text-decoration: none; font-weight: 500; }
nav[aria-label="Ruta"] ul a:hover { text-decoration: underline; }
nav[aria-label="Ruta"] ul li:last-child { color: var(--dm-text); font-weight: 500; }

/* ================================================================
   BUTTONS — belt-and-suspenders override PicoCSS
   ================================================================ */
button:not([class*="secondary"]):not([class*="outline"]):not([class*="contrast"]):not(.bottom-btn):not(.tool-btn):not(.nav-action-btn):not(.nav-logout-btn),
[type="submit"] {
  background-color: var(--dm-magenta) !important;
  border-color:     var(--dm-magenta) !important;
  color:            #ffffff !important;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
}

button:not([class*="secondary"]):not([class*="outline"]):not([class*="contrast"]):not(.bottom-btn):not(.tool-btn):not(.nav-action-btn):not(.nav-logout-btn):hover,
[type="submit"]:hover {
  background-color: var(--dm-magenta-dark) !important;
  border-color:     var(--dm-magenta-dark) !important;
}

button[class*="secondary"][class*="outline"],
[role="button"][class*="secondary"][class*="outline"] {
  background: transparent !important;
  border-color: var(--dm-border) !important;
  color: var(--dm-text) !important;
}

button[class*="secondary"][class*="outline"]:hover,
[role="button"][class*="secondary"][class*="outline"]:hover {
  border-color: var(--dm-magenta) !important;
  color: var(--dm-magenta) !important;
  background: var(--dm-magenta-light) !important;
}

.nav-logout-btn {
  background: transparent !important;
  border: 1px solid var(--dm-border) !important;
  color: var(--dm-text-secondary) !important;
  font-size: 0.75rem !important;
  padding: 0.25em 0.6em !important;
  border-radius: 5px !important;
  cursor: pointer;
  transition: all .12s;
}
.nav-logout-btn:hover {
  border-color: var(--dm-magenta) !important;
  color: var(--dm-magenta) !important;
  background: var(--dm-magenta-light) !important;
}

/* ================================================================
   FORMS (general)
   ================================================================ */
input, select, textarea {
  font-family: 'Inter', system-ui, sans-serif !important;
  font-size: 0.875rem !important;
  border-radius: 7px !important;
  border-color: var(--dm-border) !important;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--dm-magenta) !important;
  box-shadow: 0 0 0 3px rgba(179,12,115,.12) !important;
}
label { font-weight: 600; font-size: 0.82rem; }

/* ================================================================
   LOGIN PAGE
   ================================================================ */
.login-page-body {
  min-height: calc(100vh - var(--dm-navbar-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--dm-bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--dm-surface);
  border: 1px solid var(--dm-border);
  border-radius: 14px;
  box-shadow: 0 4px 32px rgba(0,0,0,.07);
  padding: 2.25rem 2rem;
}

.login-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-logo img {
  height: 48px;
  width: auto;
  margin-bottom: 0.5rem;
}

.login-brand-name {
  display: block;
  font-size: 2.1rem;
  font-weight: 700;
  font-family: 'Francisco Serial Light', 'Inter', system-ui, sans-serif;
  color: var(--dm-text);
  letter-spacing: -0.01em;
  line-height: 1.1;
  margin: 0;
}

.login-brand-tagline {
  display: block;
  font-size: 0.75rem;
  color: var(--dm-text-muted);
  margin-top: 0.15rem;
}

.login-footer {
  text-align: center;
  margin: 1.25rem 0 0;
  font-size: 0.66rem;
  color: var(--dm-text-muted);
  letter-spacing: 0.02em;
}

/* ================================================================
   TEMPLATE EDITOR
   ================================================================ */
.learn-card { max-width: 680px; margin: 0 auto; }

.step-hint { font-size: 0.78rem; color: var(--dm-text-muted); margin-top: -.35rem; margin-bottom: .875rem; }

#schema-preview {
  background: var(--dm-bg);
  border: 1px solid var(--dm-border);
  border-radius: 6px;
  padding: .875rem;
  font-size: 0.78rem;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  white-space: pre-wrap;
  min-height: 80px;
}

#btn-learn { min-width: 150px; }

#learn-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--dm-magenta);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: none;
  vertical-align: middle;
  margin-left: 0.4rem;
}

.learn-error {
  color: #991b1b; background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 6px; padding: .45rem .875rem;
  font-size: 0.82rem; margin-top: .5rem; display: none;
}

.success-banner {
  display: none; background: #f0fdf4; color: #166534;
  border: 1px solid #86efac; border-radius: 6px;
  padding: .65rem .875rem; margin-top: .875rem; font-size: 0.82rem;
}
.success-banner a { color: #166534 !important; font-weight: 700; }

.tmpl-fields { font-size: 0.74rem; color: var(--dm-text-muted); margin-top: .12rem; }

/* ================================================================
   EMPTY STATE
   ================================================================ */
.empty-state {
  text-align: center; padding: 3rem 2rem;
  color: var(--dm-text-muted);
  background: var(--dm-surface);
  border: 1px solid var(--dm-border);
  border-radius: 8px;
}
.empty-state h3 { color: var(--dm-text-muted); font-size: 1rem; }

/* ================================================================
   RAW TRANSCRIPT / RECORDING STATUS
   ================================================================ */
.raw-transcript-box {
  background: var(--dm-bg);
  border-left: 3px solid var(--dm-magenta);
  padding: .75rem .875rem;
  border-radius: 0 6px 6px 0;
  font-size: 0.82rem;
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
  line-height: 1.55;
}
.pii-note { font-size: 0.7rem; color: var(--dm-text-muted); margin-top: .2rem; }

/* Processing spinner */
#processing-spinner {
  display: flex; align-items: center; gap: .65rem;
  justify-content: center; margin-top: .65rem;
  color: var(--dm-text-muted); font-size: 0.82rem;
}
.spinner-icon {
  width: 18px; height: 18px;
  border: 2px solid var(--dm-magenta);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   COLLAPSIBLE SECTIONS (sidebar + detail footer)
   ================================================================ */
details summary {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--dm-text-secondary);
  cursor: pointer;
  user-select: none;
  padding: 0.3rem 0;
}
details[open] summary { color: var(--dm-magenta); }

/* ================================================================
   CARDS (general article override)
   ================================================================ */
article {
  border: 1px solid var(--dm-border);
  border-radius: 8px;
  background: var(--dm-surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}

/* ================================================================
   MODALES (dialogs nativos)
   ================================================================ */
dialog.ditto-modal {
  max-width: 440px;
  width: 90vw;
  border: 1px solid var(--dm-border);
  border-radius: 14px;
  box-shadow: 0 12px 48px rgba(0,0,0,.18);
  padding: 0;
  background: var(--dm-surface);
}

dialog.ditto-modal article {
  margin: 0;
  border: none;
  box-shadow: none;
  border-radius: 14px;
  padding: 1.5rem;
}

dialog.ditto-modal article header {
  padding: 0 0 0.875rem;
  border-bottom: 1px solid var(--dm-border);
  margin-bottom: 1rem;
}

dialog.ditto-modal article footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 0 0;
  border-top: 1px solid var(--dm-border);
  margin-top: 1rem;
}

dialog::backdrop {
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(3px);
}

/* ================================================================
   TOOL SEARCH MODAL (CUPS / CIE-10 / INVIMA)
   PicoCSS v2: <dialog> = full-screen overlay flex container
               <dialog > article> = the visible white box
   We must target article, not dialog, for sizing/layout.
   ================================================================ */

/* The article IS the modal box — constrain it, not the dialog */
dialog.tool-search-modal > article {
  max-width: 600px !important;          /* override Pico's 700px */
  width: min(600px, 92vw) !important;
  max-height: min(80vh, 640px) !important;
  height: min(80vh, 640px) !important;
  overflow: hidden !important;          /* children scroll, not article */
  padding: 0 !important;               /* override Pico's article padding */
  margin: auto !important;             /* center in the flex overlay */
  display: flex !important;
  flex-direction: column !important;
  border-radius: 14px !important;
  border: 1px solid var(--dm-border) !important;
  box-shadow: 0 20px 60px rgba(0,0,0,.22) !important;
  background: var(--dm-bg) !important;
}

.tool-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--dm-border);
  flex-shrink: 0;
}

.tool-modal-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.tool-modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dm-text-muted);
  font-size: 1.1rem;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.tool-modal-close:hover {
  background: var(--dm-surface);
  color: var(--dm-text);
}

.tool-modal-search {
  padding: 0.75rem 1rem 0.5rem;
  flex-shrink: 0;
}

.tool-modal-search input[type="search"] {
  width: 100%;
  margin: 0;
}

.tool-modal-status {
  font-size: 0.72rem;
  color: var(--dm-text-muted);
  min-height: 1rem;
  margin: 0.2rem 0 0;
}

.tool-modal-results {
  overflow-y: auto;
  padding: 0.25rem 0.5rem 0.75rem;
  flex: 1;
}

.tool-result-item {
  padding: 0.5rem 0.625rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.tool-result-item:hover,
.tool-result-item:focus {
  background: var(--dm-surface);
  border-color: var(--dm-border);
  outline: none;
}

.tool-result-item:active {
  background: color-mix(in srgb, var(--dm-magenta) 8%, var(--dm-surface));
}

.tool-result-code {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--dm-magenta);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.tool-result-name {
  font-size: 0.82rem;
  color: var(--dm-text);
  line-height: 1.35;
}

.tool-result-sub {
  font-size: 0.7rem;
  color: var(--dm-text-muted);
}

.tool-result-copied {
  background: color-mix(in srgb, #16a34a 10%, var(--dm-surface)) !important;
  border-color: #16a34a !important;
}

.tool-result-cie11 {
  color: #0369a1;
  font-size: 0.7rem;
}

.tool-result-cie11 strong {
  font-weight: 700;
}

/* tool-modal-status feedback state */
.tool-modal-status {
  transition: color 0.15s;
}

/* ================================================================
   POWERED BY ATTRIBUTION
   ================================================================ */
.powered-by {
  font-size: 0.65rem;
  color: var(--dm-text-muted);
  text-align: right;
  margin-top: 2rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--dm-border-light);
  letter-spacing: 0.03em;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; height: auto; overflow: auto; }
  .app-sidebar {
    width: 100%; max-width: 100%; border-right: none;
    border-bottom: 1px solid var(--dm-border);
  }
  .app-main { height: auto; }
  .nav-tabs { display: none; }
  main.container { padding-top: 1.25rem; }
}

.sidebar-badge {
  display: inline-block;
  background: #b30c73;
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
  margin-left: 0.4rem;
  vertical-align: middle;
}
