:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --danger: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14151a;
    --panel: #1c1d24;
    --text: #e8e8ec;
    --text-muted: #9497a3;
    --border: #2c2d36;
    --accent: #3b82f6;
    --danger: #f87171;
  }
}

:root[data-theme="dark"] {
  --bg: #14151a;
  --panel: #1c1d24;
  --text: #e8e8ec;
  --text-muted: #9497a3;
  --border: #2c2d36;
  --accent: #3b82f6;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  margin: 0;
}

.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen[hidden] {
  display: none !important;
}

/* ---------- login ---------- */

#screen-login {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.avatar-lg {
  width: 64px;
  height: 64px;
  font-size: 32px;
}

.login-card h1 {
  font-size: 18px;
  margin: 0 0 8px;
  text-align: center;
}

.login-card input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14.5px;
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card button[type="submit"] {
  width: 100%;
  padding: 11px;
  margin-top: 6px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin: 0;
}

/* ---------- admin ---------- */

.simple-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.simple-header h1 {
  font-size: 17px;
  margin: 0;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 2px 9px;
  margin-left: 8px;
  vertical-align: middle;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13.5px;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--border);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  overflow-x: auto;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tab-content[hidden] {
  display: none !important;
}

.admin-main {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.upload-card,
.list-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}

.upload-card h2,
.list-card h2 {
  font-size: 15px;
  margin: 0 0 14px;
}

#upload-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#upload-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-muted);
}

#upload-form input,
#upload-form select {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  outline: none;
}

#upload-form input:focus,
#upload-form select:focus {
  border-color: var(--accent);
}

#upload-form button[type="submit"] {
  margin-top: 4px;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.status-text {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.plantillas-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.plantilla-group-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 14px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.plantilla-group-title:first-child {
  margin-top: 0;
}

.plantilla-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.plantilla-item .p-info {
  flex: 1;
  min-width: 0;
}

.plantilla-item .p-name {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plantilla-item .p-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.plantilla-item .p-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 6px;
}

.plantilla-item .p-delete:hover {
  background: var(--bg);
}

.empty-hint {
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- panel de administracion ---------- */

.admin-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-top: 2px dashed var(--border);
  padding-top: 24px;
}

.section-title {
  font-size: 16px;
  margin: 0;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.inline-form input {
  flex: 1;
  min-width: 140px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  outline: none;
}

.inline-form button {
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 14px;
  cursor: pointer;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-row {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.id-tag {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.chips {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
}

.chip-x {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
}

.admin-assign-row {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.admin-assign-row select {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12.5px;
}

.admin-assign-row button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12.5px;
  cursor: pointer;
}

.toggle-global-btn {
  color: var(--accent);
  border-color: var(--accent) !important;
}
