/* ── Territory Chat ─────────────────────────────────────────────────────── */

.tiq-chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    flex-direction: column;
    gap: 12px;
}

/* ── Shell ──────────────────────────────────────────────────────────────── */

.tiq-chat-shell {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
    background: #F7F7F5;
}

.tiq-chat-shell--memory {
    height: auto;
    min-height: calc(100vh - 56px);
    overflow: visible;
}

/* ── Chat column ────────────────────────────────────────────────────────── */

.tiq-chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    min-width: 0;
    transition: flex 0.3s ease;
    background: #F7F7F5;
}

.tiq-chat-main--memory {
    height: auto;
    overflow: visible;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.tiq-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 28px 16px;
    border-bottom: 1px solid #E8E8E6;
    background: #F7F7F5;
    flex-shrink: 0;
}

.tiq-chat-header-inner {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tiq-chat-header-title {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    background: linear-gradient(90deg, #14532d 0%, #166534 60%, #15803d 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tiq-chat-header-sub {
    font-size: 0.82rem;
    color: #9ca3af;
}

.tiq-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tiq-chat-map-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: transparent;
    color: #6b7280;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s;
}

.tiq-chat-map-toggle:hover {
    border-color: #9ca3af;
    color: #374151;
}

.tiq-chat-map-toggle--active {
    border-color: #00B27A;
    color: #00B27A;
    background: rgba(0, 178, 122, 0.06);
}

.tiq-chat-map-toggle--active:hover {
    background: rgba(0, 178, 122, 0.12);
    color: #00B27A;
}

/* ── Thread ─────────────────────────────────────────────────────────────── */

.tiq-chat-thread {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    background: #F7F7F5;
}

.tiq-chat-thread::-webkit-scrollbar { width: 5px; }
.tiq-chat-thread::-webkit-scrollbar-track { background: transparent; }
.tiq-chat-thread::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* ── Messages ───────────────────────────────────────────────────────────── */

.tiq-chat-msg {
    display: flex;
    max-width: 100%;
}

.tiq-chat-msg--user {
    justify-content: flex-end;
}

.tiq-chat-msg--assistant {
    justify-content: flex-start;
    align-items: flex-start;
}

.tiq-chat-bubble {
    max-width: 72%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.65;
}

.tiq-chat-msg--user .tiq-chat-bubble {
    background: #ffffff;
    color: #1A1A1A;
    border: 1px solid #E8E8E6;
    max-width: 60%;
    border-radius: 12px 12px 2px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.tiq-chat-msg--assistant .tiq-chat-bubble {
    background: transparent;
    color: #1A1A1A;
    max-width: 88%;
    padding-left: 0;
}

.tiq-chat-avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #00B27A;
    color: #ffffff;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    margin-top: 2px;
    flex-shrink: 0;
}

.tiq-chat-bubble--streaming {
    opacity: 0.85;
}

.tiq-chat-bubble p {
    margin: 0 0 0.7em;
}

.tiq-chat-bubble p:last-child {
    margin-bottom: 0;
}

.tiq-map-replay-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    font-size: 0.72rem;
    color: #94a3b8;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 0;
    opacity: 0.6;
    transition: opacity 0.15s, color 0.15s;
    letter-spacing: 0.01em;
}
.tiq-map-replay-btn:hover {
    opacity: 1;
    color: #00B27A;
}

.tiq-chat-error {
    font-size: 0.82rem;
    color: #dc2626;
    padding: 8px 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
}

/* ── Input bar ──────────────────────────────────────────────────────────── */

.tiq-chat-input-bar {
    padding: 14px 20px 16px;
    border-top: 1px solid #E8E8E6;
    background: #F7F7F5;
    flex-shrink: 0;
}

.tiq-chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #ffffff;
    border: 1px solid #E8E8E6;
    border-radius: 12px;
    padding: 10px 12px;
    transition: border-color 0.15s;
}

.tiq-chat-input-row:focus-within {
    border-color: #00B27A;
}

.tiq-chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #1A1A1A;
    font-size: 0.88rem;
    line-height: 1.5;
    resize: none;
    min-height: 22px;
    max-height: 200px;
    height: auto;
    font-family: inherit;
    overflow-y: hidden;
}

.tiq-chat-input::placeholder {
    color: #9ca3af;
}

.tiq-chat-send {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: none;
    background: #00B27A;
    color: #fff;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.tiq-chat-send:hover:not(:disabled) {
    background: #00c98a;
}

.tiq-chat-send:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.tiq-chat-input-hint {
    margin-top: 7px;
    font-size: 0.72rem;
    color: #9ca3af;
    text-align: center;
}

/* ── Map panel — stays dark (Mapbox canvas) ─────────────────────────────── */

.tiq-chat-map-panel {
    width: 44%;
    min-width: 360px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #E8E8E6;
    flex-shrink: 0;
    animation: tiq-chat-map-slide-in 0.25s ease;
}

@keyframes tiq-chat-map-slide-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

.tiq-chat-map-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #F7F7F5;
    border-bottom: 1px solid #E8E8E6;
    flex-shrink: 0;
}

.tiq-chat-layer-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid #E8E8E6;
    background: #ffffff;
    color: #6b7280;
    font-size: 0.74rem;
    cursor: pointer;
    transition: all 0.15s;
}

.tiq-chat-layer-btn:hover {
    border-color: #9ca3af;
    color: #374151;
}

.tiq-chat-layer-btn--active {
    border-color: #00B27A;
    color: #00B27A;
    background: rgba(0, 178, 122, 0.06);
}

.tiq-chat-layer-btn--disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.tiq-chat-layer-btn--close {
    margin-left: auto;
    padding: 4px 8px;
}

.tiq-chat-map-canvas {
    flex: 1;
    min-height: 0;
}

/* ── Chat list panel ─────────────────────────────────────────────────────── */

.tiq-chat-list-panel {
    background: #ffffff;
    border-bottom: 1px solid #E8E8E6;
    max-height: 280px;
    overflow-y: auto;
    flex-shrink: 0;
}

.tiq-chat-list-panel::-webkit-scrollbar { width: 4px; }
.tiq-chat-list-panel::-webkit-scrollbar-track { background: transparent; }
.tiq-chat-list-panel::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 2px; }

.tiq-chat-list-new {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding: 11px 20px;
    background: transparent;
    border: none;
    border-bottom: 1px solid #E8E8E6;
    color: #00B27A;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s;
    text-align: left;
}

.tiq-chat-list-new:hover {
    background: rgba(0, 178, 122, 0.06);
}

.tiq-chat-list-item {
    display: flex;
    align-items: center;
    padding: 0 8px 0 20px;
    min-height: 40px;
    gap: 4px;
    transition: background 0.1s;
}

.tiq-chat-list-item:hover {
    background: #F7F7F5;
}

.tiq-chat-list-item--active {
    background: rgba(0, 178, 122, 0.05);
}

.tiq-chat-list-item-title {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: transparent;
    border: none;
    padding: 10px 0;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
}

.tiq-chat-list-item-name {
    font-size: 0.83rem;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.tiq-chat-list-item--active .tiq-chat-list-item-name {
    color: #14532d;
    font-weight: 600;
}

.tiq-chat-list-item-date {
    font-size: 0.73rem;
    color: #9ca3af;
    white-space: nowrap;
    flex-shrink: 0;
}

.tiq-chat-list-item-rename-btn {
    flex-shrink: 0;
    background: transparent;
    border: none;
    padding: 5px 7px;
    color: #d1d5db;
    cursor: pointer;
    border-radius: 5px;
    display: flex;
    align-items: center;
    transition: color 0.1s, background 0.1s;
    opacity: 0;
}

.tiq-chat-list-item:hover .tiq-chat-list-item-rename-btn {
    opacity: 1;
}

.tiq-chat-list-item-rename-btn:hover {
    color: #6b7280;
    background: #F0F0EE;
}

.tiq-chat-list-rename {
    flex: 1;
    background: #ffffff;
    border: 1px solid #00B27A;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.83rem;
    color: #1A1A1A;
    outline: none;
    font-family: inherit;
}

.tiq-chat-list-empty {
    padding: 14px 20px;
    font-size: 0.81rem;
    color: #9ca3af;
}

/* ── Memory panel ─────────────────────────────────────────────────────────── */

.tiq-mem-panel {
    display: flex;
    flex-direction: column;
    animation: tiq-mem-fade-in 0.15s ease;
}

.tiq-mem-nodes {
    padding: 20px 28px 40px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tiq-mem-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 28px 10px;
    border-bottom: 1px solid #E8E8E6;
    flex-shrink: 0;
}

.tiq-mem-toolbar-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #6b7280;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.tiq-mem-distill-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 7px;
    border: 1px solid #d1d5db;
    background: transparent;
    color: #6b7280;
    font-size: 0.76rem;
    cursor: pointer;
    transition: all 0.15s;
}

.tiq-mem-distill-btn:hover:not(:disabled) {
    border-color: #00B27A;
    color: #00B27A;
    background: rgba(0, 178, 122, 0.05);
}

.tiq-mem-distill-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@keyframes tiq-mem-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}


.tiq-mem-card {
    background: #ffffff;
    border: 1px solid #E8E8E6;
    border-radius: 10px;
    overflow: hidden;
}

.tiq-mem-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 8px;
    border-bottom: 1px solid #F3F3F1;
    gap: 12px;
}

.tiq-mem-card-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: #374151;
    letter-spacing: 0.01em;
    text-transform: uppercase;
}

.tiq-mem-card-meta {
    font-size: 0.72rem;
    color: #9ca3af;
    white-space: nowrap;
}

.tiq-mem-card-body {
    padding: 10px 14px 14px;
    font-size: 0.82rem;
    color: #374151;
    line-height: 1.6;
}

.tiq-mem-card-body--empty {
    color: #9ca3af;
    font-style: italic;
}

.tiq-mem-card-body strong {
    font-weight: 600;
    color: #1A1A1A;
}

.tiq-mem-restore {
    display: block;
    width: 100%;
    padding: 7px 14px;
    background: transparent;
    border: none;
    border-top: 1px solid #F3F3F1;
    color: #9ca3af;
    font-size: 0.72rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.tiq-mem-restore:hover {
    background: #FAFAF8;
    color: #6b7280;
}

/* ── Memory editor (bottom input area) ──────────────────────────────────── */

.tiq-mem-editor {
    border-top: 1px solid #E8E8E6;
    background: #F7F7F5;
    flex-shrink: 0;
    padding: 12px 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tiq-mem-response {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.tiq-mem-response-avatar {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #00B27A;
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}

.tiq-mem-response-text {
    font-size: 0.84rem;
    color: #374151;
    line-height: 1.55;
}

.tiq-mem-input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #ffffff;
    border: 1px solid #E8E8E6;
    border-radius: 10px;
    padding: 8px 10px;
    transition: border-color 0.15s;
}

.tiq-mem-input-row:focus-within {
    border-color: #00B27A;
}
