/* ============================================================
   gateway.css — Semantic Gateway–specific styles
   Loaded AFTER style.css (the shared SimplySemantics base)
   ============================================================ */

/* ---- TOP NAV (Gateway-specific tabs + user info) ---- */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 20px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.top-nav .logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
}

.top-nav .logo svg {
    width: 24px;
    height: 24px;
}

.top-nav .nav-links {
    display: flex;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.top-nav .nav-links button {
    background: none;
    border: none;
    color: var(--grey);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.top-nav .nav-links button:hover {
    background: #fff5f0;
    color: var(--primary);
}

.top-nav .nav-links button.active {
    background: #fff5f0;
    color: var(--primary);
    font-weight: 600;
}

.top-nav .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--grey);
}

.top-nav .user-info .tier-badge {
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    background: #fff5f0;
    color: var(--primary);
}

/* Hide nav-links and user-info when not authenticated */
body.not-authenticated .top-nav .nav-links,
body.not-authenticated .top-nav .user-info {
    display: none;
}

/* ---- AUTH PROMPT ---- */
#auth-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 56px);
    gap: 16px;
    padding: 40px 20px;
}

#auth-prompt h2 {
    font-size: 24px;
    color: var(--dark);
}

#auth-prompt p {
    color: var(--grey);
    max-width: 480px;
    text-align: center;
    line-height: 1.6;
}

#auth-prompt a {
    padding: 12px 30px;
    background: var(--primary);
    color: white;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    font-size: 16px;
    transition: background 0.3s;
}

#auth-prompt a:hover {
    background: var(--primary-dark);
}

/* ---- MAIN APP LAYOUT ---- */
#app {
    display: none;
    height: calc(100vh - 56px);
    overflow: hidden;
}

.main-layout {
    display: flex;
    height: 100%;
}

/* ---- SIDEBAR ---- */
.sidebar {
    width: 240px;
    min-width: 240px;
    background: #fff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--grey);
    margin-bottom: 10px;
    margin-top: 0;
    letter-spacing: 0.8px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    transition: background 0.2s;
}

.sidebar-item:hover {
    background: var(--light);
}

.sidebar-item.active {
    background: #fff5f0;
    color: var(--primary);
    font-weight: 600;
}

/* ---- CONTENT AREA ---- */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.content-header h2 {
    font-size: 18px;
    margin-bottom: 0;
}

.content-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ---- FLOW CANVAS ---- */
.flow-canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    cursor: grab;
    background:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: 0 0;
    background-color: var(--light);
}

.flow-canvas-container:active {
    cursor: grabbing;
}

.flow-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

/* ---- FLOW NODES ---- */
.flow-node {
    position: absolute;
    min-width: 170px;
    background: #fff;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: grab;
    user-select: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: box-shadow 0.2s, border-color 0.2s;
    z-index: 3;
    pointer-events: auto;
}

.flow-node:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.flow-node.active-node {
    border-color: var(--success);
    box-shadow: 0 0 16px rgba(40,167,69,0.25);
}

.flow-node.selected {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(255,102,0,0.2);
}

.flow-node.connecting-source {
    border-color: var(--accent-blue);
    box-shadow: 0 0 14px rgba(0,102,255,0.2);
}

.flow-node .node-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px 8px 0 0;
    color: var(--dark);
}

.flow-node .node-body {
    padding: 8px 14px;
    font-size: 12px;
    color: var(--grey);
    line-height: 1.5;
}

/* Node type header colors */
.flow-node[data-type="input"] .node-header,
.flow-node[data-type="start"] .node-header       { background: #d4edda; color: #155724; }
.flow-node[data-type="end"] .node-header          { background: #f8d7da; color: #721c24; }
.flow-node[data-type="decision"] .node-header,
.flow-node[data-type="conditional"] .node-header  { background: #fff3cd; color: #856404; }
.flow-node[data-type="llm_prompt"] .node-header   { background: #e8daef; color: #6c3483; }
.flow-node[data-type="api_call"] .node-header     { background: #d1ecf1; color: #0c5460; }
.flow-node[data-type="db_query"] .node-header     { background: #d1ecf1; color: #0c5460; }
.flow-node[data-type="tts_output"] .node-header   { background: #ffecd2; color: #e67e22; }
.flow-node[data-type="sms_output"] .node-header   { background: #d5f5f6; color: #117a8b; }
.flow-node[data-type="call_transfer"] .node-header { background: #fff5f0; color: var(--primary); }
.flow-node[data-type="call_bridge"] .node-header  { background: #fff5f0; color: var(--primary); }
.flow-node[data-type="agent_handoff"] .node-header { background: #e8daef; color: #6c3483; }
.flow-node[data-type="gather_input"] .node-header { background: #fff3cd; color: #856404; }
.flow-node[data-type="set_variable"] .node-header { background: #d5f5f6; color: #117a8b; }
.flow-node[data-type="wait"] .node-header         { background: #fff3cd; color: #856404; }

/* Node connection ports */
.node-port {
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--primary);
    cursor: crosshair;
    z-index: 10;
    transition: background 0.15s;
    pointer-events: auto;
    box-shadow: 0 0 0 3px rgba(255,102,0,0.12);
}

.node-port.port-in {
    top: -9px;
    left: 50%;
    transform: translateX(-50%);
}

.node-port.port-out {
    bottom: -9px;
    left: 50%;
    transform: translateX(-50%);
}

.node-port:hover {
    background: var(--primary);
}

.flow-node.connecting-source .node-port.port-out {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 4px rgba(0,102,255,0.18);
}

/* SVG edges */
.flow-edges {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    z-index: 1;
}

.flow-edge-hitbox {
    fill: none;
    stroke: transparent;
    pointer-events: stroke;
    cursor: pointer;
}

.flow-edge {
    fill: none;
    stroke-width: 2;
    opacity: 0.75;
    pointer-events: stroke;
    cursor: pointer;
    stroke-linecap: round;
}

.flow-edges text {
    fill: var(--grey);
    font-size: 11px;
    pointer-events: none;
}

/* ---- NODE PALETTE ---- */
.node-palette {
    padding: 4px 0;
}

.palette-node {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    margin-bottom: 4px;
    border-radius: 6px;
    font-size: 13px;
    cursor: grab;
    background: var(--light);
    border: 1px solid transparent;
    transition: all 0.15s;
    color: var(--text);
}

.palette-node:hover {
    border-color: var(--primary);
    background: #fff5f0;
}

.palette-node .p-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
}

/* ---- SIMULATOR PANEL ---- */
.simulator-panel {
    width: 320px;
    min-width: 320px;
    background: #fff;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.simulator-panel .sim-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--dark);
}

.sim-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.sim-msg {
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.5;
}

.sim-msg.system    { background: var(--light); color: var(--grey); }
.sim-msg.user      { background: #d1ecf1; color: #0c5460; }
.sim-msg.assistant  { background: #d4edda; color: #155724; }
.sim-msg.agent     { background: #e8daef; color: #6c3483; }
.sim-msg.connector { background: #ffecd2; color: #e67e22; }

.sim-input {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.sim-input input {
    flex: 1;
    padding: 8px 12px;
}

#sim-ai-assist-panel textarea {
    width: 100%;
    resize: vertical;
    min-height: 74px;
}

#sim-ai-output code {
    display: inline-block;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-assist-modal {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 62vh;
    overflow-y: auto;
    padding-right: 4px;
}

.ai-assist-section h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
}

.ai-assist-kv {
    font-size: 12px;
    color: var(--text-dim, #666);
    margin-bottom: 4px;
}

.ai-assist-diagnosis {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    line-height: 1.5;
}

.ai-assist-diagnosis p,
.ai-assist-card-body p,
.ai-assist-proposed p {
    margin: 0 0 8px 0;
}

.ai-assist-diagnosis p:last-child,
.ai-assist-card-body p:last-child,
.ai-assist-proposed p:last-child {
    margin-bottom: 0;
}

.ai-assist-list {
    margin: 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-assist-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    background: #fff;
}

.ai-assist-card-title {
    font-weight: 700;
    margin-bottom: 4px;
}

.ai-assist-node {
    display: inline-block;
    margin-bottom: 6px;
    color: var(--text-dim, #666);
    font-size: 12px;
}

.ai-assist-card-body {
    font-size: 13px;
    color: var(--text-dim, #666);
    margin-bottom: 8px;
}

.ai-assist-proposed {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    font-size: 12px;
    line-height: 1.5;
}

.ai-assist-code {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    font-size: 12px;
}

.ai-assist-empty {
    color: var(--text-dim, #666);
    font-size: 13px;
}

/* ---- VOICE TEST STATUS ---- */
.voice-status {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: #f8f9fa;
    gap: 8px;
}

.voice-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
}

.voice-indicator .voice-pulse {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    transition: background 0.3s;
}

.voice-indicator.idle .voice-pulse {
    background: #adb5bd;
}

.voice-indicator.listening .voice-pulse {
    background: #28a745;
    animation: voicePulse 1s ease-in-out infinite;
}

.voice-indicator.speaking .voice-pulse {
    background: #007bff;
    animation: voicePulse 0.6s ease-in-out infinite;
}

.voice-indicator.processing .voice-pulse {
    background: #fd7e14;
    animation: voiceSpin 1s linear infinite;
}

.voice-indicator.ended .voice-pulse {
    background: #dc3545;
}

@keyframes voicePulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.5); opacity: 0.6; }
}

@keyframes voiceSpin {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(1.2); }
    100% { transform: rotate(360deg) scale(1); }
}

.sim-msg.user-voice {
    background: #cce5ff;
    color: #004085;
    border-left: 3px solid #007bff;
}

.sim-msg.tts-audio {
    background: #d4edda;
    color: #155724;
    border-left: 3px solid #28a745;
    cursor: pointer;
}

.sim-msg.tts-audio:hover {
    background: #c3e6cb;
}

.sim-msg .replay-btn {
    display: inline-block;
    margin-left: 6px;
    font-size: 11px;
    color: #155724;
    cursor: pointer;
    opacity: 0.7;
}

.sim-msg .replay-btn:hover {
    opacity: 1;
}

/* Chat test message styles in simulator */
.sim-msg.chat-user {
    background: #fff5f0;
    color: var(--dark);
    border-left: 3px solid var(--primary);
    font-weight: 500;
}

.sim-msg.chat-assistant {
    background: #f0f4f8;
    color: var(--dark);
    border-left: 3px solid var(--accent-blue);
}

/* ---- BUTTON HELPERS (Gateway-specific aliases) ---- */
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-icon { width: 34px; height: 34px; padding: 0; display: flex; align-items: center; justify-content: center; }

/* ---- FLOW EDITOR TOOLBAR ---- */
.flow-toolbar {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 50;
    background: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 900px) {
    .sidebar { width: 200px; min-width: 200px; }
    .simulator-panel { width: 260px; min-width: 260px; }
    .top-nav .nav-links button { padding: 6px 10px; font-size: 12px; }
}

/* ---- Chat Interface ---- */
.chat-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.chat-sidebar {
    width: 260px;
    min-width: 220px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: #fafafa;
}

.chat-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.chat-sidebar-header h3 {
    font-size: 16px;
    margin: 0;
}

.chat-sidebar-section {
    padding: 12px 16px;
}

.chat-session-item {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.15s;
}

.chat-session-item:hover {
    background: var(--border);
}

.chat-session-item.active {
    background: #fff5f0;
    border-left: 3px solid var(--primary);
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-main-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
}

.chat-active-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-bubble-user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-bubble-assistant {
    align-self: flex-start;
    background: #f0f0f0;
    color: var(--dark);
    border-bottom-left-radius: 4px;
}

.chat-bubble-system {
    align-self: center;
    background: transparent;
    color: var(--grey);
    font-size: 12px;
    padding: 4px 8px;
    max-width: 90%;
    text-align: center;
}

.chat-input-bar {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    background: #fff;
}

.chat-input-bar input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input-bar input:focus {
    border-color: var(--primary);
}

@media (max-width: 768px) {
    .top-nav { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
    .top-nav .nav-links { flex-wrap: wrap; gap: 2px; }
    .sidebar { display: none; }
    .simulator-panel { width: 100%; min-width: auto; }
    .chat-sidebar { width: 200px; min-width: 160px; }
}

.configure-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.configure-sidebar {
    width: 200px;
    min-width: 200px;
    border-right: 1px solid var(--border);
    padding: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    background: var(--bg, #fafafa);
}

.configure-sidebar-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-dim, #888);
    padding: 0 16px 10px;
    margin: 0;
}

.configure-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    padding: 9px 16px;
    font-size: 14px;
    cursor: pointer;
    color: var(--text, #333);
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}

.configure-menu-item:hover {
    background: rgba(0,0,0,.04);
}

.configure-menu-item.active {
    background: rgba(var(--primary-rgb, 59,130,246), .08);
    color: var(--primary, #3b82f6);
    font-weight: 600;
    border-left-color: var(--primary, #3b82f6);
}

.configure-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

.configure-panel {
    display: none;
}

.configure-panel.active {
    display: block;
}

/* ---- SESSION DETAIL TABS ---- */
.session-tab {
    font-size: 12px !important;
    padding: 6px 12px !important;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-dim, #666);
    transition: all 0.15s;
}

.session-tab.active {
    background: var(--accent, #3b82f6);
    color: #fff;
    border-color: var(--accent, #3b82f6);
}

.session-tab:hover:not(.active) {
    background: rgba(59, 130, 246, 0.08);
}

/* ---- TRACE TIMELINE ---- */
.trace-expand {
    transition: max-height 0.2s;
}

.trace-expand.hidden {
    display: none;
}

/* ---- UTILITY ---- */
.hidden {
    display: none !important;
}
