/* =====================================================================
   DedicaQR — Sprint 18 CSS
   Notificaciones in-app: bell widget, dropdown, admin tables,
   user preferences matrix con toggle switches.
   Aditivo sobre Sprints 1-17.
   ===================================================================== */

:root {
  --notif-info-bg:      #dbeafe;
  --notif-info:         #1d4ed8;
  --notif-warning-bg:   #fef3c7;
  --notif-warning:      #b45309;
  --notif-critical-bg:  #fee2e2;
  --notif-critical:     #dc2626;
  --notif-marketing-bg: #fce7f3;
  --notif-marketing:    #be185d;
  --notif-system-bg:    #e0e7ff;
  --notif-system:       #4338ca;
}

/* =====================================================================
   BELL WIDGET (header)
   ===================================================================== */

.dqr-bell {
  position: relative;
  display: inline-block;
  z-index: 200;
}

.dqr-bell-btn {
  background: transparent;
  border: 0;
  cursor: pointer;
  position: relative;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.dqr-bell-btn:hover { background: rgba(0, 0, 0, 0.05); }
.dqr-bell--open .dqr-bell-btn { background: rgba(201, 24, 74, 0.1); }

.dqr-bell-icon {
  font-size: 20px;
  line-height: 1;
  display: inline-block;
  transition: transform 0.3s;
}
.dqr-bell--has-unread .dqr-bell-icon {
  animation: dqr-bell-shake 1.2s ease-in-out;
}
@keyframes dqr-bell-shake {
  0%, 100% { transform: rotate(0deg); }
  10%, 30%, 50% { transform: rotate(-12deg); }
  20%, 40%, 60% { transform: rotate(12deg); }
  70% { transform: rotate(-6deg); }
  80% { transform: rotate(6deg); }
}

.dqr-bell-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--dqr-brand, #C9184A);
  color: white;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 0 0 2px white;
}

/* =====================================================================
   DROPDOWN
   ===================================================================== */

.dqr-bell-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  width: 380px;
  max-width: 90vw;
  max-height: 480px;
  background: white;
  border: 1px solid #ececec;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dqr-bell-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  background: #fafafa;
}
.dqr-bell-head strong { font-size: 14px; }
.dqr-bell-mark-all {
  background: none;
  border: 0;
  font-size: 11px;
  color: var(--dqr-brand, #C9184A);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.dqr-bell-mark-all:hover { background: rgba(201, 24, 74, 0.08); }

.dqr-bell-list {
  flex: 1;
  overflow-y: auto;
  max-height: 360px;
}

.dqr-bell-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-top: 1px solid #f0f0f0;
  background: #fafafa;
  font-size: 13px;
}
.dqr-bell-foot a {
  color: var(--dqr-brand, #C9184A);
  text-decoration: none;
  font-weight: 600;
}
.dqr-bell-foot a:hover { text-decoration: underline; }
.dqr-bell-prefs {
  font-size: 16px;
  padding: 2px 6px;
}

/* States */
.dqr-bell-loading,
.dqr-bell-error,
.dqr-bell-empty {
  padding: 32px 16px;
  text-align: center;
  color: #999;
  font-size: 13px;
}
.dqr-bell-error { color: var(--notif-critical, #dc2626); }

/* =====================================================================
   BELL DROPDOWN ITEMS
   ===================================================================== */

.dqr-bell-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #f5f5f5;
  position: relative;
  transition: background 0.1s;
}
.dqr-bell-item:hover { background: #fafafa; }
.dqr-bell-item:last-child { border-bottom: 0; }

.dqr-bell-item--unread { background: rgba(255, 248, 245, 0.7); }
.dqr-bell-item--unread:hover { background: rgba(255, 248, 245, 1); }

/* Borde lateral por categoría */
.dqr-bell-item--info { border-left: 3px solid var(--notif-info); }
.dqr-bell-item--warning { border-left: 3px solid var(--notif-warning); }
.dqr-bell-item--critical { border-left: 3px solid var(--notif-critical); }
.dqr-bell-item--marketing { border-left: 3px solid var(--notif-marketing); }
.dqr-bell-item--system { border-left: 3px solid var(--notif-system); }

.dqr-bell-item-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.dqr-bell-item-content { flex: 1; min-width: 0; }

.dqr-bell-item-title {
  font-size: 13px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 2px;
  line-height: 1.3;
  word-break: break-word;
}
.dqr-bell-item--unread .dqr-bell-item-title { color: #000; }

.dqr-bell-item-body {
  font-size: 12px;
  color: #666;
  line-height: 1.4;
  margin-bottom: 6px;
  word-break: break-word;
}

.dqr-bell-item-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}
.dqr-bell-item-meta small { color: #999; }
.dqr-bell-item-action {
  color: var(--dqr-brand, #C9184A);
  text-decoration: none;
  font-weight: 600;
  font-size: 11px;
}
.dqr-bell-item-action:hover { text-decoration: underline; }

.dqr-bell-item-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dqr-brand, #C9184A);
  border: 0;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 6px;
  padding: 0;
}
.dqr-bell-item-dot:hover { background: #8c1234; }

/* =====================================================================
   ADMIN — Stats row + distribución
   ===================================================================== */

.notif-stat-row { margin: 14px 0 20px; }

.notif-dist-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 14px 0;
}
@media (max-width: 768px) {
  .notif-dist-row { grid-template-columns: 1fr; }
}

.notif-dist-card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: #1a1a1a;
}

.notif-dist-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.notif-cat-row {
  display: grid;
  grid-template-columns: 110px 1fr 60px;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
}
.notif-cat-label { font-weight: 600; font-size: 12px; }
.notif-cat-bar {
  display: block;
  background: #f3f3f3;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
}
.notif-cat-bar > span {
  display: block;
  height: 100%;
  border-radius: 4px;
}
.notif-cat-row.notif-cat--info .notif-cat-bar > span { background: var(--notif-info); }
.notif-cat-row.notif-cat--warning .notif-cat-bar > span { background: var(--notif-warning); }
.notif-cat-row.notif-cat--critical .notif-cat-bar > span { background: var(--notif-critical); }
.notif-cat-row.notif-cat--marketing .notif-cat-bar > span { background: var(--notif-marketing); }
.notif-cat-row.notif-cat--system .notif-cat-bar > span { background: var(--notif-system); }

.notif-cat-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #888;
  font-size: 12px;
}

.notif-types-list {
  margin: 0;
  padding-left: 24px;
  font-size: 13px;
}
.notif-types-list li {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}
.notif-types-list code {
  background: #f6f6f6;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
}

/* =====================================================================
   ADMIN TABLE — categoría pills
   ===================================================================== */

.notif-cat-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.notif-cat-pill.notif-cat--info       { background: var(--notif-info-bg);      color: var(--notif-info); }
.notif-cat-pill.notif-cat--warning    { background: var(--notif-warning-bg);   color: var(--notif-warning); }
.notif-cat-pill.notif-cat--critical   { background: var(--notif-critical-bg);  color: var(--notif-critical); }
.notif-cat-pill.notif-cat--marketing  { background: var(--notif-marketing-bg); color: var(--notif-marketing); }
.notif-cat-pill.notif-cat--system     { background: var(--notif-system-bg);    color: var(--notif-system); }

.notif-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}
.notif-pill-unread { background: var(--notif-warning-bg); color: var(--notif-warning); }

.notif-row-unread { background: #fff8f5; }
.notif-row-unread td:first-child::before {
  content: '●';
  color: var(--dqr-brand, #C9184A);
  margin-right: 4px;
}

.notif-table td { vertical-align: top; }

.tpl-inactive { opacity: 0.5; }

/* =====================================================================
   TEMPLATE EDITOR — preview
   ===================================================================== */

.tpl-preview-box {
  background: #fafafa;
  border: 1px dashed #ddd;
  padding: 14px;
  border-radius: 8px;
  font-size: 13px;
}
.tpl-preview-box strong { font-size: 14px; display: block; margin-bottom: 4px; }

/* =====================================================================
   BROADCAST
   ===================================================================== */

.brc-targets {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.brc-target-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fafafa;
  border: 1px solid #ececec;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color 0.15s, background 0.15s;
}
.brc-target-option:has(input:checked) {
  border-color: var(--dqr-brand, #C9184A);
  background: #fff8f5;
}
.brc-target-option strong { font-size: 13px; }
.brc-target-option small { color: #888; margin-left: auto; }

.brc-warn {
  background: var(--notif-warning-bg);
  color: var(--notif-warning);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 12px;
  border: 1px solid #fcd34d;
}

/* =====================================================================
   USER LIST (frontend)
   ===================================================================== */

.notif-user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 14px 0 16px;
  flex-wrap: wrap;
}
.notif-user-filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.notif-user-empty {
  text-align: center;
  padding: 60px 20px;
  color: #888;
}
.notif-user-empty p { margin: 4px 0; }

.notif-user-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.notif-user-item {
  display: flex;
  gap: 14px;
  padding: 16px 18px;
  background: white;
  border: 1px solid #ececec;
  border-radius: 12px;
  margin-bottom: 10px;
  transition: border-color 0.15s, transform 0.15s;
}
.notif-user-item:hover {
  border-color: var(--dqr-pink, #FFB3C1);
  transform: translateY(-1px);
}
.notif-user-item--unread {
  background: #fff8f5;
  border-color: var(--dqr-pink, #FFB3C1);
  box-shadow: 0 2px 8px rgba(201, 24, 74, 0.05);
}

/* Borde lateral por categoría */
.notif-user-item--info { border-left: 4px solid var(--notif-info); }
.notif-user-item--warning { border-left: 4px solid var(--notif-warning); }
.notif-user-item--critical { border-left: 4px solid var(--notif-critical); }
.notif-user-item--marketing { border-left: 4px solid var(--notif-marketing); }
.notif-user-item--system { border-left: 4px solid var(--notif-system); }

.notif-user-icon {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}
.notif-user-content { flex: 1; min-width: 0; }
.notif-user-title {
  font-size: 15px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 4px;
}
.notif-user-body {
  font-size: 13px;
  color: #555;
  line-height: 1.5;
  margin: 4px 0 8px;
}
.notif-user-meta {
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 12px;
  flex-wrap: wrap;
}
.notif-user-meta small { color: #999; }
.notif-user-action {
  color: var(--dqr-brand, #C9184A);
  text-decoration: none;
  font-weight: 600;
  font-size: 12px;
}
.notif-user-action:hover { text-decoration: underline; }
.notif-user-read { color: #059669; }

/* =====================================================================
   PREFERENCES — Matrix con toggle switches
   ===================================================================== */

.prefs-form { margin: 18px 0; }

.prefs-table {
  width: 100%;
  background: white;
  border: 1px solid #ececec;
  border-radius: 12px;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}
.prefs-table th {
  background: #fafafa;
  padding: 12px;
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #666;
  border-bottom: 1px solid #ececec;
}
.prefs-table th.prefs-channel-col {
  text-align: center;
  width: 100px;
}

.prefs-row td {
  padding: 16px 12px;
  border-bottom: 1px solid #f5f5f5;
  vertical-align: middle;
}
.prefs-row:last-child td { border-bottom: 0; }

.prefs-cat-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}
.prefs-cat-icon { font-size: 28px; line-height: 1; }
.prefs-cat-cell strong { display: block; color: #1a1a1a; font-size: 14px; }
.prefs-cat-desc {
  font-size: 12px;
  color: #777;
  margin: 2px 0 0;
  line-height: 1.4;
}

.prefs-toggle-cell { text-align: center; }

/* Toggle switch */
.prefs-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}
.prefs-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.prefs-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #d1d5db;
  border-radius: 24px;
  transition: background 0.2s;
}
.prefs-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.prefs-switch input:checked + .prefs-slider {
  background: var(--dqr-brand, #C9184A);
}
.prefs-switch input:checked + .prefs-slider::before {
  transform: translateX(20px);
}
.prefs-switch--locked {
  opacity: 0.7;
  cursor: not-allowed;
}
.prefs-switch--locked::after {
  content: '🔒';
  position: absolute;
  top: -6px;
  right: -6px;
  font-size: 10px;
  background: white;
  border-radius: 50%;
  padding: 2px;
}

.prefs-foot { margin-top: 18px; }

.prefs-info { margin-top: 24px; }
.prefs-info h3 { margin: 0 0 12px; font-size: 14px; }
.prefs-info dl { margin: 0; }
.prefs-info dt {
  font-weight: 700;
  margin-top: 10px;
  font-size: 13px;
}
.prefs-info dd {
  margin-left: 24px;
  color: #666;
  font-size: 12px;
  line-height: 1.5;
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */

@media (max-width: 768px) {
  .dqr-bell-dropdown { width: 320px; }
  .notif-stat-row { grid-template-columns: repeat(2, 1fr); }
  .prefs-table th.prefs-channel-col { width: 70px; padding: 8px 4px; }
  .prefs-row td { padding: 12px 6px; }
  .prefs-cat-icon { font-size: 22px; }
  .prefs-switch { transform: scale(0.85); }
}

@media (max-width: 480px) {
  .dqr-bell-dropdown {
    position: fixed;
    top: 56px;
    right: 8px;
    left: 8px;
    width: auto;
    max-width: none;
  }
  .notif-stat-row { grid-template-columns: 1fr; }
  .notif-user-item { padding: 12px; gap: 10px; }
  .notif-user-icon { font-size: 22px; }
  .notif-user-title { font-size: 14px; }
}
