/* ===== AI Features CSS — "Refined Industrial" ===== */
/* Copper accent: #c17f59 */

/* ─── Sparkle keyframes ─────────────────────────────────────── */
@keyframes sparkle {
    0%   { transform: scale(1) rotate(0deg); opacity: 1; }
    25%  { transform: scale(1.15) rotate(-8deg); opacity: 0.9; }
    50%  { transform: scale(0.95) rotate(6deg); opacity: 1; }
    75%  { transform: scale(1.1) rotate(-4deg); opacity: 0.85; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes sparkleGlow {
    0%   { box-shadow: 0 0 0 0 rgba(193, 127, 89, 0); }
    50%  { box-shadow: 0 0 12px 4px rgba(193, 127, 89, 0.35); }
    100% { box-shadow: 0 0 0 0 rgba(193, 127, 89, 0); }
}

@keyframes aiPanelSlideIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

@keyframes aiOverlayFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%            { transform: translateY(-6px); }
}

@keyframes messageFadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── AI Assist Button ──────────────────────────────────────── */
.ai-assist-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: linear-gradient(135deg, #c17f59 0%, #a66b47 100%);
    color: #fff;
    border: none;
    border-radius: 20px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.ai-assist-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.ai-assist-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(193, 127, 89, 0.45);
    filter: brightness(1.08);
    animation: sparkleGlow 0.8s ease infinite;
}

.ai-assist-btn:hover svg {
    animation: sparkle 0.6s ease;
}

.ai-assist-btn:active {
    transform: translateY(0);
    box-shadow: none;
    filter: brightness(0.96);
}

/* ─── AI Chat Panel ─────────────────────────────────────────── */
.ai-chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    z-index: 1100;
    animation: aiOverlayFadeIn 0.2s ease;
}

.ai-chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 100vw;
    background: #faf9f7;
    display: flex;
    flex-direction: column;
    z-index: 1101;
    box-shadow: -4px 0 32px rgba(0, 0, 0, 0.18);
    animation: aiPanelSlideIn 0.28s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Dark header */
.ai-chat-header {
    background: linear-gradient(135deg, #1a1a1f 0%, #2d2d35 100%);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(193, 127, 89, 0.3);
    flex-shrink: 0;
}

.ai-chat-header-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #c17f59 0%, #a66b47 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-chat-header-icon svg {
    width: 18px;
    height: 18px;
    color: #fff;
}

.ai-chat-header-info {
    flex: 1;
}

.ai-chat-header-title {
    font-family: 'Sora', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    display: block;
}

.ai-chat-header-sub {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.55);
    display: block;
    margin-top: 1px;
}

.ai-chat-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.ai-chat-close svg {
    width: 16px;
    height: 16px;
}

/* Job context strip */
.ai-chat-context {
    background: rgba(193, 127, 89, 0.08);
    border-bottom: 1px solid rgba(193, 127, 89, 0.18);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: #6b5c50;
    flex-shrink: 0;
}

.ai-chat-context svg {
    width: 14px;
    height: 14px;
    color: #c17f59;
    flex-shrink: 0;
}

.ai-chat-context strong {
    color: #c17f59;
    font-weight: 600;
}

/* ─── Message area ──────────────────────────────────────────── */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(193, 127, 89, 0.25);
    border-radius: 3px;
}

/* ─── Message bubbles ───────────────────────────────────────── */
.ai-message {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: messageFadeUp 0.22s ease;
}

.ai-message.user {
    align-self: flex-end;
    align-items: flex-end;
}

.ai-message.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.ai-message-header {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 5px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #a08070;
}

.ai-message-header svg {
    width: 12px;
    height: 12px;
}

.ai-message.assistant .ai-message-header {
    color: #c17f59;
}

.ai-message-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.55;
    font-family: 'DM Sans', sans-serif;
}

.ai-message.user .ai-message-bubble {
    background: #e8e4df;
    color: #2d2520;
    border-bottom-right-radius: 4px;
}

.ai-message.assistant .ai-message-bubble {
    background: #fff;
    color: #2d2520;
    border: 1px solid #e8e0d8;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* Rich content inside assistant bubble */
.ai-message-content {
    font-size: 0.875rem;
    line-height: 1.6;
    color: inherit;
}

.ai-message-content strong {
    font-weight: 600;
    color: #1a1a1f;
}

.ai-message-content ol,
.ai-message-content ul {
    margin: 8px 0 4px 18px;
    padding: 0;
}

.ai-message-content li {
    margin-bottom: 4px;
}

.ai-message-content .ai-parts-list {
    margin-top: 8px;
    background: rgba(193, 127, 89, 0.07);
    border: 1px solid rgba(193, 127, 89, 0.2);
    border-radius: 8px;
    padding: 8px 12px;
}

.ai-message-content .ai-part-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    font-size: 0.82rem;
}

.ai-message-content .ai-part-sku {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    background: rgba(193, 127, 89, 0.15);
    color: #a66b47;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 600;
}

/* Action buttons below assistant message */
.ai-message-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.ai-message-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: #fff;
    border: 1px solid #ddd8d0;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #5a4a40;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    font-family: 'DM Sans', sans-serif;
}

.ai-message-action-btn svg {
    width: 12px;
    height: 12px;
}

.ai-message-action-btn:hover {
    background: rgba(193, 127, 89, 0.08);
    border-color: rgba(193, 127, 89, 0.35);
    color: #c17f59;
}

/* ─── Typing Indicator ──────────────────────────────────────── */
.ai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e8e0d8;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.ai-typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #c17f59;
    opacity: 0.7;
    animation: typingBounce 1.2s ease infinite;
}

.ai-typing-indicator span:nth-child(2) {
    animation-delay: 0.15s;
}

.ai-typing-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

/* ─── Chat input area ───────────────────────────────────────── */
.ai-chat-input-area {
    flex-shrink: 0;
    padding: 12px 16px 16px;
    background: #fff;
    border-top: 1px solid #e8e0d8;
}

.ai-chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ai-chat-textarea {
    flex: 1;
    resize: none;
    border: 1px solid #ddd8d0;
    border-radius: 12px;
    padding: 10px 14px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    line-height: 1.4;
    color: #2d2520;
    background: #faf9f7;
    min-height: 42px;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.ai-chat-textarea::placeholder {
    color: #b0a098;
}

.ai-chat-textarea:focus {
    border-color: #c17f59;
    box-shadow: 0 0 0 3px rgba(193, 127, 89, 0.12);
    background: #fff;
}

.ai-chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #c17f59 0%, #a66b47 100%);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
}

.ai-chat-send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(193, 127, 89, 0.4);
    filter: brightness(1.06);
}

.ai-chat-send-btn:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
    box-shadow: none;
    filter: none;
}

.ai-chat-send-btn svg {
    width: 16px;
    height: 16px;
}

.ai-chat-hint {
    font-size: 0.72rem;
    color: #b0a098;
    margin-top: 6px;
    text-align: right;
}

/* ─── Route Optimizer Panel ─────────────────────────────────── */
.route-optimizer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    z-index: 1100;
    animation: aiOverlayFadeIn 0.2s ease;
}

.route-optimizer-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 100vw;
    background: #faf9f7;
    display: flex;
    flex-direction: column;
    z-index: 1101;
    box-shadow: -4px 0 32px rgba(0, 0, 0, 0.18);
    animation: aiPanelSlideIn 0.28s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Dark header (same treatment as chat) */
.route-optimizer-header {
    background: linear-gradient(135deg, #1a1a1f 0%, #2d2d35 100%);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(193, 127, 89, 0.3);
    flex-shrink: 0;
}

.route-optimizer-header-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #c17f59 0%, #a66b47 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.route-optimizer-header-icon svg {
    width: 18px;
    height: 18px;
    color: #fff;
}

.route-optimizer-header-info {
    flex: 1;
}

.route-optimizer-header-title {
    font-family: 'Sora', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    display: block;
}

.route-optimizer-header-sub {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.55);
    display: block;
    margin-top: 1px;
}

.route-optimizer-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.route-optimizer-close:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.route-optimizer-close svg {
    width: 16px;
    height: 16px;
}

/* Technician selector */
.route-optimizer-controls {
    padding: 14px 20px;
    background: #fff;
    border-bottom: 1px solid #e8e0d8;
    flex-shrink: 0;
}

.route-optimizer-controls label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: #7a6a60;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.route-tech-select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #ddd8d0;
    border-radius: 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    color: #2d2520;
    background: #faf9f7;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.route-tech-select:focus {
    border-color: #c17f59;
    box-shadow: 0 0 0 3px rgba(193, 127, 89, 0.12);
}

/* Scrollable stops area */
.route-stops-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.route-stops-area::-webkit-scrollbar {
    width: 5px;
}

.route-stops-area::-webkit-scrollbar-thumb {
    background: rgba(193, 127, 89, 0.25);
    border-radius: 3px;
}

/* Empty state */
.route-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    text-align: center;
    color: #9a8880;
}

.route-empty-state svg {
    width: 40px;
    height: 40px;
    color: #c8b8b0;
    margin-bottom: 12px;
}

.route-empty-state p {
    font-size: 0.875rem;
    margin: 0;
}

/* ─── Route stops ───────────────────────────────────────────── */
.route-stop {
    display: flex;
    gap: 14px;
    padding: 12px 0;
    cursor: default;
    transition: background 0.15s;
    border-radius: 10px;
}

.route-stop-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
    width: 32px;
}

/* Numbered copper circle */
.route-stop-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #c17f59 0%, #a66b47 100%);
    color: #fff;
    font-family: 'Sora', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(193, 127, 89, 0.3);
}

/* Dotted connector line between stops */
.route-stop-connector {
    flex: 1;
    width: 2px;
    background: repeating-linear-gradient(
        to bottom,
        #ddd8d0 0px,
        #ddd8d0 4px,
        transparent 4px,
        transparent 9px
    );
    margin: 0 auto;
    min-height: 20px;
}

.route-stop-info {
    flex: 1;
    padding-bottom: 4px;
}

.route-stop-id {
    font-family: 'Sora', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    color: #c17f59;
    margin-bottom: 2px;
}

.route-stop-customer {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1a1a1f;
    margin-bottom: 3px;
}

.route-stop-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.route-stop-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.72rem;
    padding: 2px 7px;
    border-radius: 6px;
    background: #f0ebe4;
    color: #6b5c50;
    font-weight: 500;
}

.route-stop-badge svg {
    width: 10px;
    height: 10px;
}

/* ─── Travel time row ───────────────────────────────────────── */
.route-travel-time {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0 3px 46px;
    font-size: 0.78rem;
    color: #9a8880;
}

.route-travel-time-line {
    flex: 1;
    height: 1px;
    background: repeating-linear-gradient(
        to right,
        #c8b8b0 0px,
        #c8b8b0 5px,
        transparent 5px,
        transparent 10px
    );
}

.route-travel-time-label {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    font-weight: 500;
    color: #7a6a60;
}

.route-travel-time-label svg {
    width: 12px;
    height: 12px;
    color: #c17f59;
}

/* ─── Summary bar ───────────────────────────────────────────── */
.route-summary {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid #e8e0d8;
    padding: 14px 20px;
}

.route-summary-stats {
    display: flex;
    gap: 0;
    background: #f5f3f0;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 14px;
}

.route-summary-stat {
    flex: 1;
    padding: 12px 16px;
    text-align: center;
    border-right: 1px solid #e8e0d8;
}

.route-summary-stat:last-child {
    border-right: none;
}

.route-summary-stat-value {
    display: block;
    font-family: 'Sora', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: #c17f59;
    line-height: 1;
}

.route-summary-stat-label {
    display: block;
    font-size: 0.72rem;
    color: #9a8880;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 4px;
}

.route-apply-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #c17f59 0%, #a66b47 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
    letter-spacing: 0.01em;
}

.route-apply-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(193, 127, 89, 0.4);
    filter: brightness(1.06);
}

.route-apply-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.route-apply-btn svg {
    width: 16px;
    height: 16px;
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 480px) {
    .ai-chat-panel,
    .route-optimizer-panel {
        width: 100vw;
    }
}
