:root {
    --bg-0: #07101f;
    --bg-1: #0c1729;
    --bg-2: #11203a;
    --panel: rgba(15, 27, 48, 0.72);
    --panel-border: rgba(96, 138, 200, 0.14);
    --panel-border-strong: rgba(96, 138, 200, 0.28);
    --text: #e6edf7;
    --text-dim: #8da3c2;
    --text-mute: #5e7595;
    --accent: #2f86ff;
    --accent-2: #4ea1ff;
    --accent-glow: rgba(47, 134, 255, 0.35);
    --green: #22c55e;
    --amber: #f59e0b;
    --red: #ef4444;
    --code-bg: rgba(7, 16, 31, 0.7);
  }
  
  * { box-sizing: border-box; }
  html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-0);
    color: var(--text);
    font-family: 'DM Sans', system-ui, sans-serif;
    height: 100vh;
    overflow: hidden;
  }
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
      radial-gradient(ellipse 80% 50% at 20% 0%, rgba(47, 134, 255, 0.10), transparent 60%),
      radial-gradient(ellipse 60% 50% at 90% 100%, rgba(47, 134, 255, 0.08), transparent 60%),
      linear-gradient(180deg, #07101f 0%, #060c18 100%);
    z-index: -2;
  }
  body::after {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
      linear-gradient(rgba(96, 138, 200, 0.04) 1px, transparent 1px),
      linear-gradient(90deg, rgba(96, 138, 200, 0.04) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, #000 30%, transparent 90%);
    -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, #000 30%, transparent 90%);
    z-index: -1;
    animation: drift 60s linear infinite;
  }
  @keyframes drift {
    from { background-position: 0 0, 0 0; }
    to { background-position: 480px 480px, 480px 480px; }
  }

  /* Top bar */

  .topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: rgba(8, 16, 30, 0.85);
    border-bottom: 1px solid var(--panel-border);
    backdrop-filter: blur(8px);
    height: 52px;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    font-size: 15px;
  }

  .brand .dot {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
  }

  .brand .sub {
    color: var(--text-dim);
    font-weight: 400;
    font-size: 12px;
    margin-left: 6px;
    letter-spacing: 0;
  }

  .api-bar {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(7, 14, 28, 0.6);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 6px 10px;
    max-width: 640px;
    margin: 0 auto;
  }
  .api-bar label {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--text-mute);
    letter-spacing: 0.5px;
    text-transform: uppercase;
  }

  .api-bar input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: 'DM Mono', monospace;
    font-size: 12px;
  }

  .api-bar .status {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--text-mute);
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.03);
  }

  .api-bar .status.ok { color: var(--green); background: rgba(34, 197, 94, 0.08); }
  .api-bar .status.err { color: var(--red); background: rgba(239, 68, 68, 0.08); }

  .env {
    display: flex;
    gap: 8px;
    align-items: center;
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--text-mute);
  }

.env .badge {
    padding: 3px 8px;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.02);
}

  /* Main grid */

  main {
    display: grid;
    grid-template-columns: 360px 1fr 440px;
    gap: 14px;
    padding: 14px;
    height: calc(100vh - 52px);
  }
  .panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  }

  .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.015);
  }

  .panel-title {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.3px;
  }

  .panel-title .muted {
    color: var(--text-mute);
    font-weight: 400;
    margin-left: 6px;
    font-size: 11px;
  }
  .panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
  }
  .panel-body::-webkit-scrollbar { width: 8px; }
  .panel-body::-webkit-scrollbar-track { background: transparent; }
  .panel-body::-webkit-scrollbar-thumb { background: rgba(96, 138, 200, 0.18); border-radius: 4px; }

  /* Live indicator */

  .live {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    letter-spacing: 1px;
    color: var(--green);
    background: rgba(34, 197, 94, 0.08);
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(34, 197, 94, 0.18);
  }

  .live .pulse {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
    animation: pulse 1.5s ease-in-out infinite;
  }
  @keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
  }

  /* Ticket cards */

  .ticket {
    background: rgba(13, 23, 42, 0.7);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
    transition: all 0.25s ease;
    position: relative;
  }

  .ticket:hover {
    border-color: var(--panel-border-strong);
    transform: translateY(-1px);
  }

  .ticket.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 0 24px var(--accent-glow);
    background: rgba(47, 134, 255, 0.06);
  }

  .ticket.done {
    opacity: 0.55;
  }

  .ticket-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
  }

  .ticket-id {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--accent-2);
    letter-spacing: 0.5px;
  }

  .ticket-time {
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    color: var(--text-mute);
  }

  .ticket-company {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
  }

  .ticket-contact {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 8px;
    font-family: 'DM Mono', monospace;
  }

  .ticket-issue {
    font-size: 12.5px;
    color: var(--text-dim);
    line-height: 1.5;
    margin-bottom: 12px;
    border-left: 2px solid var(--panel-border);
    padding-left: 10px;
  }

  .submit-btn {
    width: 100%;
    padding: 8px 12px;
    background: rgba(47, 134, 255, 0.12);
    color: var(--accent-2);
    border: 1px solid rgba(47, 134, 255, 0.3);
    border-radius: 6px;
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.3px;
  }

  .submit-btn:hover:not(:disabled) {
    background: rgba(47, 134, 255, 0.22);
    border-color: var(--accent);
  }

  .submit-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  .ticket.active .submit-btn {
    background: rgba(47, 134, 255, 0.2);
    color: var(--accent-2);
    border-color: var(--accent);
  }

  .processing-bar {
    height: 2px;
    width: 100%;
    margin-top: 10px;
    background: rgba(47, 134, 255, 0.15);
    overflow: hidden;
    border-radius: 2px;
    display: none;
  }

  .ticket.active .processing-bar { display: block; }
  .processing-bar::after {
    content: '';
    display: block;
    height: 100%;
    width: 30%;
    background: var(--accent);
    animation: slide 1.4s ease-in-out infinite;
  }

  @keyframes slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
  }

  /* Centre — Agent */

.agent-header-inner {
    display: flex;
    align-items: center;
    gap: 12px;
}

.rydal-logo {
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 3px;
    background: linear-gradient(135deg, #fff 0%, var(--accent-2) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    padding: 2px 0;
}

.rydal-logo::before {
    content: '◆';
    color: var(--accent);
    margin-right: 8px;
    font-size: 14px;
    background: none;
    -webkit-text-fill-color: var(--accent);
}

.agent-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    color: var(--text-mute);
    letter-spacing: 0.8px;
}

.agent-status .ind {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-mute);  
}

.agent-status.thinking .ind {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    animation: pulse 1s ease-in-out infinite;
}

.log {
    font-family: 'DM Mono', monospace;
    font-size: 12.5px;
    line-height: 1.6;
}

.log-entry {
    display: flex;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 4px;
    border-radius: 8px;
    background: rgba(13, 23, 42, 0.5);
    border: 1px solid var(--panel-border);
    opacity: 0;
    transform: translateY(6px);
    animation: enter 0.35s ease forwards;
    align-items: flex-start;
  }

@keyframes enter {
    to { opacity: 1; transform: translateY(0); }
}

.log-entry .icon {
    font-size: 14px;
    line-height: 1.5;
    width: 20px;
    flex-shrink: 0;
}

.log-entry .text {
    flex: 1;
    color: var(--text-dim);
  }
  .log-entry.complete .text { color: var(--text); }
  .log-entry .meta {
    color: var(--text-mute);
    font-size: 11px;
    margin-top: 2px;
  }
  .log-entry .ts {
    color: var(--text-mute);
    font-size: 10px;
    flex-shrink: 0;
    padding-top: 2px;
  }
  .log-entry.success { border-left: 2px solid var(--green); }
  .log-entry.escalate { border-left: 2px solid var(--amber); }
  .log-entry.error { border-left: 2px solid var(--red); }

  .typing::after {
    content: '▋';
    color: var(--accent);
    animation: blink 1s steps(1) infinite;
    margin-left: 2px;
  }
  @keyframes blink { 50% { opacity: 0; } }

  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-mute);
    text-align: center;
    gap: 14px;
  }

  .empty-state .ico {
    width: 56px;
    height: 56px;
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    background: rgba(255, 255, 255, 0.02);
  }
  .empty-state .t1 { font-size: 14px; color: var(--text-dim); font-weight: 500; }
  .empty-state .t2 { font-size: 12px; max-width: 280px; line-height: 1.5; }

  /* Resolution */
  .res-card {
    background: rgba(13, 23, 42, 0.7);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    animation: enter 0.4s ease forwards;
    opacity: 0;
  }
  .res-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .res-id {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--accent-2);
  }
  .res-company {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
  }
  .badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 14px;
  }

.badge {
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.6px;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid;
    font-weight: 500;
}

.badge.p1 { color: var(--red); border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.08); }
.badge.p2 { color: var(--amber); border-color: rgba(245, 158, 11, 0.4); background: rgba(245, 158, 11, 0.08); }
.badge.p3 { color: var(--green); border-color: rgba(34, 197, 94, 0.4); background: rgba(34, 197, 94, 0.08); }
.badge.cat { color: var(--accent-2); border-color: rgba(47, 134, 255, 0.35); background: rgba(47, 134, 255, 0.08); }
.badge.resolved { color: var(--green); border-color: rgba(34, 197, 94, 0.5); background: rgba(34, 197, 94, 0.12); }
.badge.escalated { color: var(--amber); border-color: rgba(245, 158, 11, 0.5); background: rgba(245, 158, 11, 0.12); }

.section-label {
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    letter-spacing: 1px;
    color: var(--text-mute);
    text-transform: uppercase;
    margin-bottom: 6px;
    margin-top: 4px;
}

  .response-box {
    background: var(--code-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 12px;
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
  }

  .esc-card {
    background: rgba(245, 158, 11, 0.04);
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: 8px;
    padding: 12px;
    margin-top: 10px;
  }

  .esc-card .row {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 12px;
  }

  .esc-card .k {
    font-family: 'DM Mono', monospace;
    color: var(--text-mute);
    min-width: 90px;
    font-size: 11px;
  }

  .esc-notes {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.55;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(245, 158, 11, 0.15);
    white-space: pre-wrap;
  }

.reset-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    color: var(--text-dim);
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.reset-btn:hover {
    border-color: var(--panel-border-strong);
    color: var(--text);
}

.footer-bar {
    padding: 10px 12px;
    border-top: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.01);
}

/* Steff agent tagline */
.agent-title-block {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
.agent-tagline {
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    color: var(--text-mute);
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* Email thread badge + button on resolution card */
.badge.email-thread-badge {
    color: var(--accent-2);
    border-color: rgba(47, 134, 255, 0.35);
    background: rgba(47, 134, 255, 0.10);
}
.open-email-btn {
    width: 100%;
    margin-top: 14px;
    padding: 10px 12px;
    background: linear-gradient(135deg, rgba(47, 134, 255, 0.18), rgba(47, 134, 255, 0.10));
    color: var(--accent-2);
    border: 1px solid rgba(47, 134, 255, 0.4);
    border-radius: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: all 0.2s ease;
}
.open-email-btn:hover {
    background: linear-gradient(135deg, rgba(47, 134, 255, 0.28), rgba(47, 134, 255, 0.16));
    border-color: var(--accent);
    box-shadow: 0 0 18px var(--accent-glow);
}

/* ============= Email Modal ============= */
.email-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 32px;
}
.email-modal.open {
    display: flex;
    animation: modalFade 0.25s ease forwards;
}
@keyframes modalFade {
    from { opacity: 0; }
    to { opacity: 1; }
}
.email-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(3, 8, 18, 0.72);
    backdrop-filter: blur(6px);
}
.email-modal-card {
    position: relative;
    width: 100%;
    max-width: 860px;
    height: min(86vh, 760px);
    background: linear-gradient(180deg, rgba(15, 27, 48, 0.98) 0%, rgba(11, 22, 42, 0.98) 100%);
    border: 1px solid var(--panel-border-strong);
    border-radius: 16px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(47, 134, 255, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.96);
    opacity: 0;
    animation: modalScale 0.28s cubic-bezier(.2,.9,.3,1.1) forwards;
}
@keyframes modalScale {
    to { transform: scale(1); opacity: 1; }
}
.email-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.02);
}
.email-modal-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.3px;
}
.email-modal-sub {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--text-mute);
    margin-top: 2px;
    letter-spacing: 0.4px;
}
.email-modal-close {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--panel-border);
    color: var(--text-dim);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s ease;
}
.email-modal-close:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.4);
    color: var(--red);
}
.email-thread {
    flex: 1;
    overflow-y: auto;
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background:
      radial-gradient(ellipse 60% 40% at 50% 0%, rgba(47, 134, 255, 0.04), transparent 60%),
      transparent;
}
.email-thread::-webkit-scrollbar { width: 8px; }
.email-thread::-webkit-scrollbar-thumb { background: rgba(96, 138, 200, 0.18); border-radius: 4px; }

.email-msg {
    display: flex;
    gap: 10px;
    max-width: 78%;
    opacity: 0;
    transform: translateY(6px);
    animation: emailEnter 0.32s ease forwards;
}
@keyframes emailEnter {
    to { opacity: 1; transform: translateY(0); }
}
.email-msg.left { align-self: flex-start; }
.email-msg.right {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.email-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(96, 138, 200, 0.18);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    border: 1px solid var(--panel-border);
}
.email-msg.right .email-avatar,
.steff-avatar {
    background: linear-gradient(135deg, var(--accent), #1f5dc4);
    color: #fff;
    border-color: rgba(47, 134, 255, 0.55);
    box-shadow: 0 0 14px var(--accent-glow);
}
.email-bubble {
    background: rgba(13, 23, 42, 0.85);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 10px 14px;
    min-width: 120px;
}
.email-msg.right .email-bubble {
    background: rgba(47, 134, 255, 0.10);
    border-color: rgba(47, 134, 255, 0.35);
    border-left: 2px solid var(--accent);
}
.email-meta-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}
.email-msg.right .email-meta-row { flex-direction: row-reverse; }
.email-sender {
    font-weight: 600;
    font-size: 12px;
    color: var(--text);
}
.email-msg.right .email-sender { color: var(--accent-2); }
.email-time {
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    color: var(--text-mute);
}
.email-body {
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-dim);
    white-space: pre-wrap;
}
.email-msg.right .email-body { color: var(--text); }

.typing-row .email-bubble.typing-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
}
.typing-label {
    font-size: 11px;
    color: var(--text-mute);
    font-style: italic;
}
.typing-dots {
    display: inline-flex;
    gap: 4px;
}
.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-2);
    opacity: 0.4;
    animation: typingDot 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typingDot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

.email-error {
    color: var(--red);
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 12px;
    align-self: center;
}

.email-modal-footer {
    border-top: 1px solid var(--panel-border);
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.015);
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.email-modal-footer:empty { display: none; }
.email-status {
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    letter-spacing: 0.4px;
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid;
    animation: emailEnter 0.4s ease forwards;
    opacity: 0;
}
.email-status.resolved {
    color: var(--green);
    border-color: rgba(34, 197, 94, 0.4);
    background: rgba(34, 197, 94, 0.08);
}
.email-status.escalated {
    color: var(--amber);
    border-color: rgba(245, 158, 11, 0.4);
    background: rgba(245, 158, 11, 0.08);
}

@media (max-width: 720px) {
    .email-modal { padding: 0; }
    .email-modal-card {
        max-width: 100%;
        height: 100vh;
        border-radius: 0;
        border: none;
    }
    .email-msg { max-width: 92%; }
}
