/* Custom overrides for Unfold admin theme */

/* Multi-select — larger height and item indent */
select[multiple] {
    min-height: 15em !important;
    padding: 0.5rem !important;
}
select[multiple] option {
    padding: 0.25rem 0.5rem !important;
    text-indent: 0.25rem;
}

/* Chat model settings — Unfold-style checkboxes */
.chat-tool-checkbox {
    appearance: none;
    -webkit-appearance: none;
    width: 1.25rem;
    height: 1.25rem;
    min-width: 1.25rem;
    border: 1px solid var(--color-base-300, #d1d5db);
    border-radius: 4px;
    background-color: #fff;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    position: relative;
    cursor: pointer;
    display: block;
}
.dark .chat-tool-checkbox {
    background-color: var(--color-base-900, #1a1a2e);
    border-color: var(--color-base-700, #374151);
}
.chat-tool-checkbox:checked {
    background-color: var(--color-primary-600);
    border-color: var(--color-primary-600);
}
.chat-tool-checkbox:checked::after {
    content: 'check_small';
    font-family: 'Material Symbols Outlined';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    line-height: 1;
    color: #fff;
}
.chat-tool-checkbox:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Double the default WYSIWYG (Trix) editor min-height from 5em to 10em */
trix-editor {
    min-height: 12em !important;
}

/* Sidebar — active item slightly darker background */
#nav-sidebar-inner ol a.active {
    background-color: oklch(96.4% .020 236.824) !important;  /* primary-50~100 */
}
.dark #nav-sidebar-inner ol a.active {
    background-color: oklch(29.3% .066 243.157 / 0.5) !important;  /* primary-950 @ 50% */
}

/* Sidebar — larger icons and slightly bigger font for all items */
#nav-sidebar-inner .material-symbols-outlined.md-18 {
    font-size: 22px !important;
    width: 22px !important;
}
#nav-sidebar-inner ol a span:not(.material-symbols-outlined) {
    font-size: 0.9375rem !important;  /* 15px */
}

/* Sidebar icon colors — Tickets (green), Tasks (blue) */
#nav-sidebar-inner a[href="/admin/tickets/ticket/"] .material-symbols-outlined {
    color: #059669 !important;  /* emerald-600 */
}
#nav-sidebar-inner a[href="/admin/tickets/task/"] .material-symbols-outlined {
    color: #0074b8 !important;
}

.dark #nav-sidebar-inner a[href="/admin/tickets/ticket/"] .material-symbols-outlined {
    color: #34d399 !important;  /* emerald-400 */
}
.dark #nav-sidebar-inner a[href="/admin/tickets/task/"] .material-symbols-outlined {
    color: #38bdf8 !important;  /* sky-400 — lighter variant of #0074b8 for dark mode */
}

/* Ticket/Task key link colors in tables and dashboard */
.zoe-ticket-key {
    font-weight: 600;
    color: #059669;  /* emerald-600 */
}
.zoe-ticket-key:hover {
    color: #047857;  /* emerald-700 */
}
.dark .zoe-ticket-key {
    color: #34d399;  /* emerald-400 */
}
.dark .zoe-ticket-key:hover {
    color: #a7f3d0;  /* emerald-200 */
}

.zoe-task-key {
    font-weight: 600;
    color: #0074b8;
}
.zoe-task-key:hover {
    color: #0074b8;
}
.dark .zoe-task-key {
    color: #38bdf8;  /* sky-400 — lighter variant of #0074b8 for dark mode */
}
.dark .zoe-task-key:hover {
    color: #38bdf8;
}

/* ========================================
   Ticket Detail — Two-column layout
   ======================================== */

/* Message bubbles */
.ticket-msg {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border-left-width: 4px;
    border-left-style: solid;
    transition: box-shadow 0.15s ease;
}
.ticket-msg:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}
.ticket-msg-incoming {
    border-left-color: #3b82f6;
    background-color: #eff6ff;
}
.dark .ticket-msg-incoming {
    background-color: rgba(59, 130, 246, 0.1);
}
.ticket-msg-outgoing {
    border-left-color: #22c55e;
    background-color: #f0fdf4;
}
.dark .ticket-msg-outgoing {
    background-color: rgba(34, 197, 94, 0.1);
}
.ticket-msg-internal_note {
    border-left-color: #f59e0b;
    background-color: #fffbeb;
}
.dark .ticket-msg-internal_note {
    background-color: rgba(245, 158, 11, 0.1);
}
.ticket-msg-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.ticket-msg-author {
    font-weight: 600;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}
.ticket-msg-badge {
    font-size: 0.65rem;
    font-weight: 500;
    padding: 0.1rem 0.5rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}
.ticket-msg-badge-incoming {
    background-color: #dbeafe;
    color: #0074b8;
}
.dark .ticket-msg-badge-incoming {
    background-color: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}
.ticket-msg-badge-outgoing {
    background-color: #dcfce7;
    color: #15803d;
}
.dark .ticket-msg-badge-outgoing {
    background-color: rgba(34, 197, 94, 0.2);
    color: #86efac;
}
.ticket-msg-badge-internal_note {
    background-color: #fef3c7;
    color: #92400e;
}
.dark .ticket-msg-badge-internal_note {
    background-color: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}
.ticket-msg-time {
    font-size: 0.7rem;
    opacity: 0.6;
    margin-left: auto;
}
.ticket-msg-body {
    font-size: 0.875rem;
    line-height: 1.6;
}
.ticket-msg-body p {
    margin-bottom: 0.5rem;
}
.ticket-msg-body p:last-child {
    margin-bottom: 0;
}

/* Status badges — colors now come from inline styles via Status model */

/* Priority badge */
.ticket-priority-high {
    color: #dc2626;
    font-weight: 600;
}
.dark .ticket-priority-high {
    color: #f87171;
}

/* Reply form styling */
.ticket-reply-form .aligned {
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 0.5rem;
    padding: 1rem;
}
.dark .ticket-reply-form .aligned {
    border-color: var(--dark-border-color, #374151);
}

/* Sidebar property row */
.ticket-property-label {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-font-subtle-light);
}
.dark .ticket-property-label {
    color: var(--color-font-subtle-dark);
}
.ticket-property-value {
    font-size: 0.875rem;
}

/* Linked Tasks — remove button */
.linked-task-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    color: var(--color-font-subtle-light);
    transition: all 0.15s ease;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
}
.linked-task-remove:hover {
    background-color: #fee2e2;
    color: #dc2626;
}
.dark .linked-task-remove {
    color: var(--color-font-subtle-dark);
}
.dark .linked-task-remove:hover {
    background-color: rgba(220, 38, 38, 0.2);
    color: #f87171;
}

/* Linked Tasks — autocomplete select full width (Select2 sets inline width) */
.linked-tasks-add .select2-container,
.linked-tasks-add select {
    width: 100% !important;
    min-width: 0;
}

/* ========================================
   Task Detail — Two-column layout
   ======================================== */

/* Task status badges — colors now come from inline styles via Status model */

/* Task priority badge (high/urgent) */
.task-priority-high {
    color: #dc2626;
    font-weight: 600;
}
.dark .task-priority-high {
    color: #f87171;
}

/* Task description prose styling */
.task-description {
    font-size: 0.875rem;
    line-height: 1.7;
}
.task-description p {
    margin-bottom: 0.75rem;
}
.task-description p:last-child {
    margin-bottom: 0;
}
.task-description a {
    color: var(--color-primary-600);
    text-decoration: underline;
}
.task-description ul,
.task-description ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}
.task-description li {
    margin-bottom: 0.25rem;
}

/* Task merge banner */
.task-merge-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}
.dark .task-merge-banner {
    background-color: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
    border-color: rgba(245, 158, 11, 0.3);
}

/* Task tag pills */
.task-tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.1rem 0.5rem;
    border-radius: 9999px;
    border: 1px solid #d1d5db;
    background: transparent;
}
.dark .task-tag-pill {
    border-color: #4b5563;
}

/* Task description card — remove Unfold card p-6 so editor uses full width */
.card-no-padding {
    padding: 0 !important;
    flex-grow: 0 !important;
}

/* Compact card — reduce Unfold p-6 to p-4, adjust title bar negative margins */
.card-compact {
    padding: 1rem !important;
}
.card-compact > .border-b {
    margin: -1rem -1rem 1rem !important;
    padding: 0.75rem 1rem !important;
}

/* WYSIWYG editors — full width, no bottom margin on field wrappers */
.task-description-editor .max-w-4xl,
.ticket-reply-form .max-w-4xl {
    max-width: 100% !important;
}
.task-description-editor trix-editor {
    min-height: 32em !important;
}
.ticket-reply-form trix-editor {
    min-height: 13em !important;
}
.task-description-editor .mb-4,
.ticket-reply-form .mb-4 {
    margin-bottom: 0 !important;
}

/* Minimalist attachment thumbnails (shared across tasks, notes, tickets) */
.task-att-thumb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--color-base-300);
    transition: border-color 0.15s, opacity 0.15s;
    text-decoration: none;
}
.task-att-thumb:has(img) {
    width: 36px;
}
.task-att-thumb:has(.task-att-name) {
    width: auto;
    gap: 2px;
    padding: 0 6px;
}
.dark .task-att-thumb {
    border-color: var(--color-base-600);
}
.task-att-thumb:hover {
    border-color: var(--color-primary-500);
    opacity: 0.85;
}
.task-att-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.task-att-thumb .material-symbols-outlined {
    font-size: 18px;
    color: var(--color-font-subtle-light);
}
.dark .task-att-thumb .material-symbols-outlined {
    color: var(--color-font-subtle-dark);
}
.task-att-name {
    font-size: 11px;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-font-subtle-light);
}
.dark .task-att-name {
    color: var(--color-font-subtle-dark);
}

/* Tag toggle pills — replace checkbox list with pill buttons */
/* Django CheckboxSelectMultiple renders: #id_tags > div > label > input */
#tags-wrapper #id_tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

#tags-wrapper #id_tags > div {
    display: inline-flex;
}

#tags-wrapper #id_tags > div label {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 0.3125rem 0.75rem;
    border-radius: 9999px;
    border: 1px solid #d1d5db;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    white-space: nowrap;
}

#tags-wrapper #id_tags > div label:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.dark #tags-wrapper #id_tags > div label {
    border-color: #4b5563;
}

.dark #tags-wrapper #id_tags > div label:hover {
    background-color: rgba(255, 255, 255, 0.06);
}

#tags-wrapper #id_tags > div input[type="checkbox"] {
    display: none;
}

/* Selected state — filled pill */
#tags-wrapper #id_tags > div:has(input:checked) label {
    background-color: var(--color-primary-100, #dbeafe);
    border-color: var(--color-primary-400, #60a5fa);
    color: var(--color-primary-700, #1d4ed8);
}

.dark #tags-wrapper #id_tags > div:has(input:checked) label {
    background-color: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.4);
    color: #93c5fd;
}

/* Tags collapse — hide unchecked when collapsed (if 8+ tags) */
.tags-collapsed > div:has(input:not(:checked)) {
    display: none;
}
/* If no tags selected and collapsed, show all (nothing to collapse to) */
.tags-collapsed:not(:has(input:checked)) > div {
    display: inline-flex;
}

/* Detail sidebar — prevent cards from stretching to fill column height */
#task-detail-sidebar > div,
#detail-sidebar > div {
    flex-grow: 0 !important;
}

/* Properties/merge/linked forms — remove bottom margin from last field */
#task-detail-sidebar form .mb-4:last-child,
#detail-sidebar form .mb-4:last-child {
    margin-bottom: 0 !important;
}

/* Merge autocomplete select full width (Select2 sets inline width) */
.merge-card-form .select2-container,
.merge-card-form select {
    width: 100% !important;
    min-width: 0;
}

/* ========================================
   Task Checklists
   ======================================== */

/* Checklist card */
.checklist-card {
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    background: transparent;
}
.dark .checklist-card {
    border-color: #374151;
}

/* Progress bar */
.checklist-progress-track {
    width: 100%;
    height: 8px;
    background-color: #e5e7eb;
    border-radius: 9999px;
    overflow: hidden;
}
.dark .checklist-progress-track {
    background-color: #374151;
}
.checklist-progress-fill {
    height: 100%;
    border-radius: 9999px;
    background-color: #3b82f6;
    transition: width 0.3s ease;
    min-width: 2px;
}
.checklist-progress-complete {
    background-color: #22c55e;
}

/* Checked item text */
.checklist-item-checked {
    text-decoration: line-through;
    color: #9ca3af;
}
.dark .checklist-item-checked {
    color: #6b7280;
}

/* Checkbox icons */
.checklist-checkbox {
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    line-height: 1;
    transition: transform 0.1s ease;
}
.checklist-checkbox:hover {
    transform: scale(1.15);
}
.checklist-checkbox:active {
    transform: scale(0.95);
}
.checklist-icon-checked {
    color: #22c55e;
}
.dark .checklist-icon-checked {
    color: #4ade80;
}
.checklist-icon-unchecked {
    color: #9ca3af;
}
.dark .checklist-icon-unchecked {
    color: #6b7280;
}
.checklist-icon-unchecked:hover {
    color: #6b7280;
}
.dark .checklist-icon-unchecked:hover {
    color: #9ca3af;
}

/* Drag handle icons — always visible, subtle, move cursor on hover */
.checklist-handle-icon {
    color: #d1d5db;
    transition: color 0.15s ease;
}
.checklist-drag-handle:hover,
.checklist-card-drag-handle:hover {
    cursor: move;
}
.checklist-drag-handle:hover .checklist-handle-icon,
.checklist-card-drag-handle:hover .checklist-handle-icon {
    color: #9ca3af;
}
.dark .checklist-handle-icon {
    color: #4b5563;
}
.dark .checklist-drag-handle:hover .checklist-handle-icon,
.dark .checklist-card-drag-handle:hover .checklist-handle-icon {
    color: #9ca3af;
}

/* SortableJS ghost/chosen states — items */
.checklist-item-ghost {
    opacity: 0.4;
    background-color: #dbeafe;
    border-radius: 0.375rem;
}
.dark .checklist-item-ghost {
    background-color: rgba(59, 130, 246, 0.15);
}
.checklist-item-chosen {
    background-color: #f3f4f6;
    border-radius: 0.375rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.dark .checklist-item-chosen {
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* SortableJS ghost/chosen states — checklist cards */
.checklist-card-ghost {
    opacity: 0.4;
    border-color: #93c5fd;
}
.checklist-card-chosen {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}
.dark .checklist-card-chosen {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Hide completed items toggle */
.checklist-hide-completed .checklist-item-row[data-checked="true"] {
    display: none;
}

/* Add item textarea — auto-grow, min 3 lines on focus */
.checklist-add-textarea {
    min-height: 2em;
    max-height: 12em;
    overflow-y: hidden;
    line-height: 1.5;
    transition: min-height 0.15s ease;
}
.checklist-add-textarea:focus {
    min-height: 4.5em;
}

/* Action buttons (hide completed, delete) */
.checklist-action-btn {
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    white-space: nowrap;
    transition: color 0.15s ease;
}

/* ========================================
   Attachment thumbnails
   ======================================== */
.zoe-thumbnail {
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    vertical-align: middle;
    border: 1px solid #e5e7eb;
}
.dark .zoe-thumbnail {
    border-color: #374151;
}

/* Message attachments in ticket detail bubbles */
.ticket-msg-attachments {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.dark .ticket-msg-attachments {
    border-top-color: rgba(255, 255, 255, 0.08);
}

/* Chat markdown rendering */
.chat-markdown {
    line-height: 1.6;
}
.chat-markdown p {
    margin-bottom: 0.5em;
}
.chat-markdown p:last-child {
    margin-bottom: 0;
}
.chat-markdown h1, .chat-markdown h2, .chat-markdown h3 {
    font-weight: 600;
    margin-top: 0.75em;
    margin-bottom: 0.25em;
}
.chat-markdown h1 { font-size: 1.15em; }
.chat-markdown h2 { font-size: 1.05em; }
.chat-markdown h3 { font-size: 1em; }
.chat-markdown ul, .chat-markdown ol {
    padding-left: 1.5em;
    margin-bottom: 0.5em;
}
.chat-markdown ul { list-style-type: disc; }
.chat-markdown ol { list-style-type: decimal; }
.chat-markdown li { margin-bottom: 0.2em; }
.chat-markdown code {
    background-color: rgba(0,0,0,0.06);
    padding: 0.15em 0.35em;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: ui-monospace, monospace;
}
.dark .chat-markdown code {
    background-color: rgba(255,255,255,0.1);
}
.chat-markdown pre {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 0.75em 1em;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 0.5em;
    font-size: 0.8em;
}
.chat-markdown pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}
.chat-markdown blockquote {
    border-left: 3px solid #d1d5db;
    padding-left: 0.75em;
    color: #6b7280;
    margin-bottom: 0.5em;
}
.dark .chat-markdown blockquote {
    border-left-color: #4b5563;
    color: #9ca3af;
}
.chat-markdown table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 0.5em;
    font-size: 0.85em;
}
.chat-markdown th, .chat-markdown td {
    border: 1px solid #d1d5db;
    padding: 0.35em 0.6em;
    text-align: left;
}
.dark .chat-markdown th, .dark .chat-markdown td {
    border-color: #4b5563;
}
.chat-markdown th {
    background-color: rgba(0,0,0,0.04);
    font-weight: 600;
}
.dark .chat-markdown th {
    background-color: rgba(255,255,255,0.05);
}
.chat-markdown strong { font-weight: 600; }
.chat-markdown em { font-style: italic; }
.chat-markdown a {
    color: var(--color-primary-600);
    text-decoration: underline;
}
.chat-markdown hr {
    border: none;
    border-top: 1px solid #d1d5db;
    margin: 0.75em 0;
}
.dark .chat-markdown hr {
    border-top-color: #4b5563;
}

/* ========================================
   Popover — reusable hover popover
   ======================================== */
.popover-trigger-wrap {
    display: inline-block;
}
/* Allow popover to escape Unfold card overflow-hidden */
.overflow-hidden:has(.popover-trigger-wrap) {
    overflow: visible !important;
}
.popover-panel {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 9999;
    min-width: 260px;
    max-width: 360px;
    margin-top: 1px;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
/* Invisible bridge so cursor can travel from trigger to popover */
.popover-panel::before {
    content: "";
    position: absolute;
    top: -6px;
    left: 0;
    right: 0;
    height: 6px;
}
.dark .popover-panel {
    background: var(--color-bg-dark-900, #111827);
    border-color: #374151;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.popover-trigger-wrap:hover > .popover-panel:not(:empty) {
    display: block;
}

/* ── Task Discussion ──────────────────────────────── */
#discussion-form .max-w-4xl {
    max-width: 100% !important;
}
#discussion-form .mb-4 {
    margin-bottom: 0 !important;
}
.task-note-system {
    border-left: 3px solid #d1d5db;
}
.dark .task-note-system {
    border-left-color: #4b5563;
}
.note-action-btn {
    opacity: 0;
    transition: opacity 0.15s;
}
.task-note-user:hover .note-action-btn {
    opacity: 1;
}
.task-note-body p {
    margin: 0.25em 0;
}
.task-note-body a {
    color: var(--color-primary-600);
    text-decoration: underline;
}
