/* Panel de administración SDM gRPC: paleta y estilo del dashboard de SDMIsdm
   (Tailwind/Flowbite), sin build de Node. */
:root {
  --sud-50: #fef7ee; --sud-100: #fcedd8; --sud-200: #f8d6b0; --sud-400: #ed9148;
  --sud-500: #e97426; --sud-600: #da5c1c; --sud-700: #b54519; --sud-800: #90381c;
  --bg: #f9fafb; --surface: #ffffff; --surface-2: #f3f4f6; --border: #e5e7eb;
  --text: #111827; --text-2: #4b5563; --muted: #6b7280;
  --primary: var(--sud-600); --primary-hover: var(--sud-700); --primary-soft: var(--sud-50); --primary-text: var(--sud-700);
  --green-bg: #dcfce7; --green-text: #166534; --red-bg: #fee2e2; --red-text: #991b1b; --red: #dc2626;
  --yellow-bg: #fef9c3; --yellow-text: #854d0e; --gray-bg: #f3f4f6; --gray-text: #374151;
  --focus: 0 0 0 3px rgba(233, 116, 38, .35);
  --radius: .5rem; --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  color-scheme: light;
}
html.dark {
  --bg: #111827; --surface: #1f2937; --surface-2: #374151; --border: #374151;
  --text: #f9fafb; --text-2: #d1d5db; --muted: #9ca3af;
  --primary: var(--sud-600); --primary-hover: var(--sud-500); --primary-soft: rgba(233, 116, 38, .15); --primary-text: var(--sud-400);
  --green-bg: rgba(34, 197, 94, .18); --green-text: #86efac; --red-bg: rgba(239, 68, 68, .18); --red-text: #fca5a5; --red: #ef4444;
  --yellow-bg: rgba(234, 179, 8, .18); --yellow-text: #fde047; --gray-bg: #374151; --gray-text: #d1d5db;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, Figtree, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.5; background: var(--bg); color: var(--text);
}
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 .25rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .25rem; display: flex; align-items: center; gap: .4rem; }
h3 { font-size: .95rem; font-weight: 600; margin: 1.25rem 0 .4rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; overflow-x: auto; white-space: pre; }
hr { border: 0; border-top: 1px solid var(--border); margin: .75rem 0; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.strong { font-weight: 600; color: var(--text); }
.nowrap { white-space: nowrap; }
.truncate { max-width: 28rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* Layout */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 3.5rem; z-index: 40; display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { height: 1.1rem; width: auto; display: block; }
.logo-fill { fill: #1f2937; }
html.dark .logo-fill { fill: #ffffff; }
.brand-sub { font-weight: 600; font-size: .8rem; color: var(--primary-text); letter-spacing: .04em; }
.env-badge { font-size: .7rem; font-weight: 600; text-transform: uppercase; padding: .1rem .5rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary-text); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.icon-button {
  display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; border-radius: var(--radius);
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); }
.icon-button:focus-visible { outline: none; box-shadow: var(--focus); }
.icon-moon { display: none; }
html.dark .icon-sun { display: none; }
html.dark .icon-moon { display: block; }
.menu-button { display: none; }

.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: .5rem; cursor: pointer; padding: .25rem .5rem; border-radius: var(--radius); }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--surface-2); }
.avatar {
  width: 2rem; height: 2rem; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--sud-500); color: #fff; font-weight: 600;
}
.user-name { font-weight: 500; }
.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + .4rem); min-width: 14rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 10px 25px rgba(0, 0, 0, .12); padding: .4rem; z-index: 50;
}
.user-menu-panel a, .user-menu-panel button {
  display: block; width: 100%; text-align: left; padding: .5rem .75rem; border-radius: .375rem; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer;
}
.user-menu-panel a:hover, .user-menu-panel button:hover { background: var(--surface-2); text-decoration: none; }
.user-menu-email { padding: .5rem .75rem; font-size: .8rem; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: .25rem; }

.sidebar {
  position: fixed; top: 3.5rem; left: 0; bottom: 0; width: 16rem; z-index: 30; padding: .75rem;
  background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; transition: transform .2s;
}
.nav-item { display: flex; align-items: center; gap: .75rem; padding: .55rem .75rem; border-radius: var(--radius); color: var(--text); font-weight: 500; margin-bottom: .2rem; }
.nav-item .icon { color: var(--muted); }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary-text); }
.nav-item.active .icon { color: var(--primary-text); }
.main { margin-left: 16rem; padding: 5rem 1.5rem 2rem; max-width: 84rem; }

@media (max-width: 860px) {
  .menu-button { display: inline-flex; }
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; box-shadow: 0 10px 25px rgba(0, 0, 0, .2); }
  .main { margin-left: 0; padding: 4.75rem 1rem 2rem; }
  .user-name, .env-badge { display: none; }
}

/* Page */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-header p { margin: 0; }
.header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.breadcrumb { font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card-body { padding: 1.25rem; }
.card-header { padding: 1.1rem 1.25rem .5rem; }
.card-header p { margin: 0; }
.narrow { max-width: 44rem; }
.help ol { margin: .5rem 0 0; padding-left: 1.25rem; }
.help li { margin-bottom: .3rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { display: flex; flex-direction: column; gap: .25rem; padding: 1.1rem 1.25rem; margin: 0; color: var(--text); }
a.stat:hover { text-decoration: none; border-color: var(--sud-400); }
.stat-label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-warning .stat-value { color: var(--yellow-text); }

.detail-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 1rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  background: var(--surface-2); padding: .65rem 1rem; white-space: nowrap;
}
.table td { padding: .75rem 1rem; border-top: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.table .num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form { display: inline; }
.table .details { max-width: 32rem; word-break: break-word; font-size: .85rem; }
.table .empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.row-muted td { color: var(--muted); }
.row-muted .strong { color: var(--muted); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: .9rem; border-top: 1px solid var(--border); }

.toolbar { display: flex; gap: .5rem; padding: 1rem 1.25rem; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search], .toolbar input[type=text] { flex: 1 1 16rem; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; font-weight: 500; flex: 1; }
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field-row .field { min-width: 14rem; }
.required { color: var(--red); font-style: normal; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .55rem .75rem; width: 100%; min-width: 0;
}
html:not(.dark) input[type=text], html:not(.dark) input[type=email], html:not(.dark) input[type=password],
html:not(.dark) input[type=search], html:not(.dark) select, html:not(.dark) textarea { background: #f9fafb; border-color: #d1d5db; }
.toolbar select { width: auto; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--sud-500); box-shadow: var(--focus); }
textarea { resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }

.check { display: flex; align-items: center; gap: .5rem; cursor: pointer; font-weight: 400; }
.check input { width: 1rem; height: 1rem; accent-color: var(--sud-600); }
.services { display: grid; grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr)); gap: 1rem; }
.service { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0; min-width: 0; }
.service legend { display: flex; align-items: center; gap: .5rem; padding: 0 .4rem; font-weight: 600; }
.service .method { padding: .3rem 0 .3rem 1.25rem; flex-wrap: wrap; }
.method code { word-break: break-all; }

/* Integrations */
.config-fields { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0; min-width: 0; }
.config-fields legend { padding: 0 .4rem; font-weight: 600; }
.config-fields-structured { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.config-fields-structured > .config-group { grid-column: 1; width: 100%; }
.config-group { border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem 1rem; margin: .35rem 0 1rem; min-width: 0; }
.config-fields-structured > .config-group { margin: 0; }
.config-group:last-child { margin-bottom: 0; }
.config-group h3 { margin: 0 0 .8rem; font-size: 1rem; }
.config-group-grid { display: grid; grid-template-columns: repeat(var(--config-columns), minmax(0, 1fr)); gap: 1rem; }
.config-field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.config-field > label { font-weight: 500; }
.config-field { grid-column: span var(--config-span, 1); }
.config-field .check { margin-top: 1.6rem; }
.config-field.has-error input { border-color: var(--red); }
.field-error { color: var(--red-text); font-size: .8rem; }
.field-description { color: var(--muted); font-size: .8rem; }
.secret-input { display: flex; gap: .5rem; align-items: center; }
.secret-input input { flex: 1; }
.config-group-connection .config-field:first-child { max-width: 12rem; }

@media (max-width: 760px) {
  .config-group-grid { grid-template-columns: minmax(0, 1fr); }
  .config-field { grid-column: span 1; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: var(--radius);
  font: inherit; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-outline { color: var(--red); border-color: var(--red); background: transparent; }
.btn-danger-outline:hover { background: var(--red-bg); }
.btn-link { border-color: transparent; background: transparent; color: var(--primary-text); }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-block { width: 100%; }

/* Badges and alerts */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .55rem; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-red { background: var(--red-bg); color: var(--red-text); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow-text); }
.badge-gray { background: var(--gray-bg); color: var(--gray-text); }

.alert { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert-success { background: var(--green-bg); color: var(--green-text); }
.alert-error { background: var(--red-bg); color: var(--red-text); }
.alert-warning { background: var(--yellow-bg); color: var(--yellow-text); }
.alert .check { margin-top: .4rem; }
.alert-close { background: none; border: 0; color: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; opacity: .7; }
.alert-close:hover { opacity: 1; }

.danger-zone { border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }

/* Token created */
.token-meta { display: flex; gap: 2rem; flex-wrap: wrap; margin: 0 0 1rem; }
.token-meta dt { font-size: .8rem; color: var(--muted); }
.token-meta dd { margin: 0; font-weight: 600; }
.token-box { display: flex; align-items: center; gap: .75rem; padding: .9rem 1rem; border: 2px dashed var(--sud-400); border-radius: var(--radius); background: var(--primary-soft); flex-wrap: wrap; }
.token-box code { font-size: .95rem; word-break: break-all; flex: 1 1 20rem; color: var(--text); }

/* Login */
body.bare { min-height: 100vh; }
.theme-floating { position: fixed; top: 1rem; right: 1rem; }
body.bare > .alert { max-width: 26rem; margin: 1.5rem auto 0; }
.auth-wrapper { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem 1rem; }
.auth-card { width: 100%; max-width: 26rem; padding: 2rem; margin: 0; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 1.25rem; }
.auth-logo .logo { height: 1.6rem; }
.auth-title { justify-content: center; font-size: 1.25rem; margin: 0; }
.auth-subtitle { text-align: center; margin: .25rem 0 1.5rem; }
.auth-env { margin-top: 1rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }

/* Logs */
.settings-note { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 1rem; }
.settings-note .wide { grid-column: 1 / -1; }
.filters select { flex: 0 1 14rem; }
.entry-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 1rem; margin: 0 0 1rem; }
.entry-meta dt { font-size: .8rem; color: var(--muted); }
.entry-meta dd { margin: 0; font-weight: 500; word-break: break-word; }
pre code { white-space: pre-wrap; word-break: break-word; }

/* Collapsible JSON (log entry) */
.json-block { margin-top: 1rem; }
.json-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.json-head h2 { margin: 0; }
.json-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
/* Icon-only copy button: the icon turns into a check and a "Copiado" bubble shows above it. */
.btn-copy { position: relative; padding: .3rem .45rem; }
.btn-copy .icon { width: 1rem; height: 1rem; }
.btn-copy .icon-copied { display: none; color: var(--green-text); }
.btn-copy[data-copied] .icon-copy { display: none; }
.btn-copy[data-copied] .icon-copied { display: block; }
.btn-copy[data-copied]::after {
  content: attr(data-copied); position: absolute; bottom: calc(100% + .4rem); left: 50%; transform: translateX(-50%);
  padding: .2rem .5rem; border-radius: .35rem; background: var(--text); color: var(--surface);
  font-size: .72rem; font-weight: 500; white-space: nowrap; pointer-events: none; z-index: 10;
}
.json-tree { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; line-height: 1.5; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; overflow-x: auto; }
.json-tree[hidden], .json-block pre[hidden] { display: none; }
.json-tree .jt-line, .json-tree .jt-close { white-space: pre-wrap; word-break: break-word; }
.json-tree details > summary { list-style: none; cursor: pointer; border-radius: .25rem; margin-left: -1rem; padding-left: 1rem; position: relative; }
.json-tree details > summary::-webkit-details-marker { display: none; }
.json-tree details > summary::before { content: "▾"; position: absolute; left: .1rem; color: var(--muted); }
.json-tree details:not([open]) > summary::before { content: "▸"; }
.json-tree details > summary:hover { background: var(--primary-soft); }
.json-tree details > summary:focus-visible { outline: none; box-shadow: var(--focus); }
.json-tree details[open] > summary .jt-collapsed { display: none; }
.json-tree .jt-children { padding-left: 1.25rem; margin-left: .2rem; border-left: 1px dashed var(--border); }
.json-tree .jt-key { color: var(--primary-text); }
.json-tree .jt-string { color: var(--green-text); }
.json-tree .jt-number { color: #1d4ed8; }
.json-tree .jt-bool, .json-tree .jt-null { color: #7c3aed; }
.json-tree .jt-punct, .json-tree .jt-count { color: var(--muted); }
.json-tree .jt-count { font-style: italic; font-size: .9em; }
.dark .json-tree .jt-children { border-left-color: #4b5563; }
.dark .json-tree .jt-number { color: #93c5fd; }
.dark .json-tree .jt-bool, .dark .json-tree .jt-null { color: #c4b5fd; }
