/* ─────────────────────────────────────────────
   KasaDesk — tenant + HQ shared styles
   ───────────────────────────────────────────── */

:root {
    --desk-primary: #4f46e5;
    --desk-primary-dark: #4338ca;
    --desk-bg: #f8fafc;
    --desk-surface: #ffffff;
    --desk-border: #e5e7eb;
    --desk-text: #1e293b;
    --desk-text-muted: #64748b;
    --desk-hq: #7c3aed;
}

/* Page head */
.desk-page-head {
    background: #fff;
    border-bottom: 1px solid var(--desk-border);
    padding: 18px 24px 0;
    margin: 0 -15px 16px;
}
.desk-page-head.desk-hq { background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%); }
.desk-page-head-inner {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}
.desk-page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--desk-text);
    margin: 0 0 4px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.desk-page-icon { font-size: 24px; }
.desk-page-subtitle { color: var(--desk-text-muted); font-size: 13px; margin: 0; }
.desk-page-head-actions { display: flex; gap: 8px; align-items: center; }
.desk-back {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 8px; background: var(--desk-bg);
    color: var(--desk-text-muted); text-decoration: none;
    font-size: 13px; margin-right: 4px;
}
.desk-back:hover { background: var(--desk-border); color: var(--desk-text); }
.desk-mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 14px; color: var(--desk-text-muted); }

/* Sub-nav tabs */
.desk-subnav {
    display: flex;
    gap: 4px;
    padding: 0;
    border-top: 1px solid var(--desk-border);
    margin-top: 8px;
}
.desk-subnav-item {
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--desk-text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
}
.desk-subnav-item:hover { color: var(--desk-primary); }
.desk-subnav-item.active {
    color: var(--desk-primary);
    border-bottom-color: var(--desk-primary);
}
.desk-hq .desk-subnav-item.active { color: var(--desk-hq); border-bottom-color: var(--desk-hq); }

/* Buttons */
.desk-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}
.desk-btn-primary { background: var(--desk-primary); color: #fff; }
.desk-btn-primary:hover { background: var(--desk-primary-dark); color: #fff; }
.desk-btn-ghost { background: #fff; color: var(--desk-text); border-color: var(--desk-border); }
.desk-btn-ghost:hover { background: var(--desk-bg); }
.desk-btn-sm { padding: 4px 10px; font-size: 12px; }

/* Stats bar */
.desk-stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.desk-stat {
    background: #fff;
    border: 1px solid var(--desk-border);
    border-radius: 10px;
    padding: 14px 18px;
}
.desk-stat-label { font-size: 11px; font-weight: 600; color: var(--desk-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.desk-stat-value { font-size: 24px; font-weight: 700; color: var(--desk-text); margin-top: 2px; }

/* Card */
.desk-card {
    background: #fff;
    border: 1px solid var(--desk-border);
    border-radius: 10px;
    overflow: hidden;
}
.desk-card-pad { padding: 16px; }

/* Toolbar */
.desk-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.desk-toolbar .form-control { height: 36px; border-radius: 8px; font-size: 13px; }

/* Table */
.desk-table {
    width: 100%;
    border-collapse: collapse;
}
.desk-table thead th {
    padding: 10px 14px;
    background: var(--desk-bg);
    border-bottom: 1px solid var(--desk-border);
    font-size: 11px;
    font-weight: 700;
    color: var(--desk-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
}
.desk-table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--desk-border);
    font-size: 13px;
    color: var(--desk-text);
    vertical-align: middle;
}
.desk-table tbody tr:hover { background: var(--desk-bg); }
.desk-link { color: var(--desk-primary); text-decoration: none; font-weight: 600; }
.desk-link:hover { text-decoration: underline; }
.desk-muted { color: var(--desk-text-muted); font-size: 12px; }

/* Pills */
.desk-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.desk-prio-urgent { background: #fee2e2; color: #991b1b; }
.desk-prio-high { background: #ffedd5; color: #9a3412; }
.desk-prio-medium { background: #dbeafe; color: #1e40af; }
.desk-prio-low { background: #f1f5f9; color: #475569; }
.desk-status-open { background: #dbeafe; color: #1e40af; }
.desk-status-in_progress { background: #ede9fe; color: #6d28d9; }
.desk-status-waiting_customer { background: #fef3c7; color: #92400e; }
.desk-status-resolved { background: #dcfce7; color: #166534; }
.desk-status-closed { background: #f1f5f9; color: #475569; }
.desk-status-pending { background: #fef3c7; color: #92400e; }

/* Empty hero */
.desk-empty-hero {
    background: #fff;
    border: 1px dashed var(--desk-border);
    border-radius: 12px;
    padding: 44px 24px;
    text-align: center;
}
.desk-empty-hero .hero-icon { font-size: 48px; display: block; margin-bottom: 10px; }
.desk-empty-hero h3 { font-size: 18px; margin: 0 0 6px; color: var(--desk-text); }
.desk-empty-hero p { color: var(--desk-text-muted); font-size: 14px; margin: 0 0 18px; }
.desk-empty { text-align: center; padding: 30px; color: var(--desk-text-muted); font-size: 13px; }

/* Detail layout */
.desk-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
}
@media (max-width: 1024px) {
    .desk-layout { grid-template-columns: 1fr; }
}
.desk-side { display: flex; flex-direction: column; gap: 12px; }
.desk-side-title { font-size: 11px; font-weight: 700; color: var(--desk-text-muted); text-transform: uppercase; margin-bottom: 10px; }
.desk-side-row {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 13px; padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
}
.desk-side-row:last-child { border: none; }
.desk-side-row span { color: var(--desk-text-muted); }

/* Thread */
.desk-thread {
    background: #fff;
    border: 1px solid var(--desk-border);
    border-radius: 10px;
    padding: 18px;
    max-height: 60vh;
    overflow-y: auto;
}
.desk-msg { padding: 14px 0; border-bottom: 1px solid #f1f5f9; }
.desk-msg:last-child { border: none; }
.desk-msg.is-note { background: #fffbeb; border-radius: 8px; padding: 12px 14px; margin: 6px 0; border: 1px solid #fde68a; }
.desk-msg-head { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 6px; }
.desk-msg-body { font-size: 14px; color: var(--desk-text); line-height: 1.55; white-space: pre-wrap; }

/* Reply form */
.desk-reply-form {
    background: #fff;
    border: 1px solid var(--desk-border);
    border-radius: 10px;
    padding: 14px;
    margin-top: 12px;
}
.desk-reply-form textarea { border: 1px solid var(--desk-border); border-radius: 8px; font-size: 13px; }
.desk-reply-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.desk-check { font-size: 12px; color: var(--desk-text-muted); display: inline-flex; align-items: center; gap: 5px; margin: 0; }

/* Form */
.desk-form .desk-form-row { margin-bottom: 14px; }
.desk-form .desk-form-row label {
    display: block; font-size: 12px; font-weight: 600; color: var(--desk-text); margin-bottom: 4px;
}
.desk-form .desk-form-row .form-control { border-radius: 8px; font-size: 13px; }
.desk-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.desk-form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--desk-border); }
.desk-form { padding: 24px; }

/* Chat room */
.desk-chatroom {
    background: #fff;
    border: 1px solid var(--desk-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 260px);
    min-height: 440px;
    overflow: hidden;
}
.desk-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: var(--desk-bg);
}
.desk-chat-msg { display: flex; margin-bottom: 12px; }
.desk-chat-msg.self { justify-content: flex-end; }
.desk-chat-bubble {
    max-width: 60%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    background: #fff;
    border: 1px solid var(--desk-border);
}
.desk-chat-msg.self .desk-chat-bubble {
    background: var(--desk-primary);
    color: #fff;
    border-color: var(--desk-primary);
}
.desk-chat-msg.self .desk-chat-meta { color: rgba(255,255,255,0.75); }
.desk-chat-meta { font-size: 11px; color: var(--desk-text-muted); margin-bottom: 4px; }
.desk-chat-input {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: #fff;
    border-top: 1px solid var(--desk-border);
    align-items: flex-end;
}
.desk-chat-input textarea {
    flex: 1;
    border: 1px solid var(--desk-border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    font-family: inherit;
}

/* Modal */
.desk-modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,0.55);
    z-index: 9999; align-items: center; justify-content: center;
}
.desk-modal {
    background: #fff; border-radius: 12px;
    width: 100%; max-width: 520px;
    max-height: 90vh; overflow: auto;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.desk-modal-head, .desk-modal-foot {
    padding: 16px 20px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--desk-border);
}
.desk-modal-foot { border-top: 1px solid var(--desk-border); border-bottom: none; gap: 8px; justify-content: flex-end; }
.desk-modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.desk-modal-close { background: none; border: none; font-size: 24px; color: var(--desk-text-muted); cursor: pointer; line-height: 1; }
.desk-modal-body { padding: 18px 20px; }
.desk-modal-body .desk-form-row { margin-bottom: 14px; }
.desk-modal-body label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.desk-modal-body .form-control { border-radius: 8px; font-size: 13px; }

/* ─── Floating Help Bubble ─── */
.desk-help-bubble {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9990;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px 12px 14px;
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff !important;
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35), 0 2px 6px rgba(0,0,0,0.1);
    text-decoration: none !important;
    font-size: 13px;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
}
.desk-help-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.45), 0 4px 8px rgba(0,0,0,0.12);
    color: #fff !important;
}
.desk-help-bubble-icon { font-size: 18px; line-height: 1; }
.desk-help-bubble-text { white-space: nowrap; }
@media (max-width: 600px) {
    .desk-help-bubble-text { display: none; }
    .desk-help-bubble { padding: 14px; }
}

/* ─── Team DM Chat (Slack-style) ─── */
.dchat {
    display: flex;
    height: calc(100vh - 240px);
    min-height: 500px;
    background: #fff;
    border: 1px solid var(--desk-border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.dchat-people {
    width: 280px;
    border-right: 1px solid var(--desk-border);
    background: #f9fafb;
    display: flex;
    flex-direction: column;
}
.dchat-people-head { padding: 12px; border-bottom: 1px solid var(--desk-border); }
.dchat-people-head input { border-radius: 8px; font-size: 13px; }
.dchat-people-list { flex: 1; overflow-y: auto; }
.dchat-person {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    text-decoration: none !important;
    color: var(--desk-text);
    transition: background 0.15s;
}
.dchat-person:hover { background: #f1f5f9; color: var(--desk-text); }
.dchat-person.active { background: #dbeafe; border-left: 3px solid #2563eb; padding-left: 11px; }
.dchat-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.dchat-avatar.lg { width: 44px; height: 44px; font-size: 14px; }
.dchat-person-info { flex: 1; min-width: 0; }
.dchat-person-name { font-size: 13px; font-weight: 600; color: var(--desk-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dchat-person-role { font-size: 11px; color: var(--desk-text-muted); }
.dchat-unread {
    background: #ef4444;
    color: #fff;
    border-radius: 999px;
    padding: 2px 7px;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
}
.dchat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.dchat-main-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--desk-border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
}
.dchat-main-name { font-size: 15px; font-weight: 700; color: var(--desk-text); }
.dchat-main-sub { font-size: 12px; color: var(--desk-text-muted); }
.dchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.dchat-msg { display: flex; }
.dchat-msg.self { justify-content: flex-end; }
.dchat-msg.other { justify-content: flex-start; }
.dchat-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid var(--desk-border);
    font-size: 13px;
    line-height: 1.5;
    color: var(--desk-text);
}
.dchat-msg.self .dchat-bubble {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}
.dchat-meta { font-size: 10px; opacity: 0.75; margin-bottom: 4px; }
.dchat-input {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--desk-border);
    background: #fff;
    align-items: flex-end;
}
.dchat-input textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--desk-border) !important;
    border-radius: 10px !important;
    padding: 10px 12px !important;
    font-size: 13px;
    font-family: inherit;
    min-height: 40px;
    max-height: 120px;
    background: #ffffff !important;
    color: #0f172a !important;
    box-shadow: none !important;
}
.dchat-input textarea:focus {
    outline: none;
    border-color: #2563eb !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1) !important;
}
.dchat-input textarea::placeholder { color: #94a3b8 !important; }
.dchat-input button { flex-shrink: 0; }
.dchat-input-opts { padding: 4px 16px 10px; background: #fff; border-top: none; }
.dchat-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 11px; color: var(--desk-text-muted); cursor: pointer; margin: 0; font-weight: 500; }
.dchat-toggle input[type="checkbox"] { margin: 0; cursor: pointer; }
.dchat-toggle kbd { background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 4px; padding: 1px 5px; font-size: 10px; font-family: ui-monospace, monospace; color: #475569; }

/* Sidebar unread badges */
.desk-nav-badge {
    display: inline-block;
    background: #ef4444;
    color: #fff;
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
    margin-left: 6px;
    vertical-align: middle;
    line-height: 1.4;
}
.desk-parent-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    margin-left: 6px;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25);
    animation: desk-pulse 2s ease-in-out infinite;
}
@keyframes desk-pulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25); }
    50% { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15); }
}
.dchat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--desk-text-muted);
    text-align: center;
    padding: 40px;
}
.dchat-empty-icon { font-size: 48px; margin-bottom: 12px; }
.dchat-empty h3 { font-size: 16px; font-weight: 700; color: var(--desk-text); margin: 0 0 6px; }
.dchat-empty p { font-size: 13px; margin: 0; }
