/* Tasks page specific styles — compact layout (synced from Autotask To-Dos) */

/* ── Top Bar: title + user chip + admin select + stats all in one row ── */
.todos-top-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    flex-wrap: nowrap;
    min-width: 0;
}

.top-bar-spacer {
    flex: 1;
}

.todos-title-block {
    display: flex;
    flex-direction: column;
    gap: 0;
    white-space: nowrap;
}

.todos-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark-color);
    margin: 0;
    white-space: nowrap;
}

.todos-subtitle {
    font-size: 0.72rem;
    color: var(--muted-color, #6c757d);
    margin: 0;
    line-height: 1.2;
    white-space: nowrap;
}

/* User chip — small inline tag */
.user-chip {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    gap: 0.4rem;
    background: #e9ecef;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
}

.user-chip-name {
    font-weight: 700;
    color: var(--dark-color);
}

.user-chip-divider {
    color: #adb5bd;
}

.user-chip-email {
    color: var(--secondary-text);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-chip-change {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0 0.25rem;
    text-decoration: underline;
}

.user-chip-change:hover {
    color: #0056b3;
    transform: none;
    box-shadow: none;
}

/* Stat pills — compact inline badges */
.stats-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: #e8f5e9;
    color: #2e7d32;
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.stat-pill-value {
    font-weight: 800;
}

.stat-pill-danger {
    background: #f8d7da;
    color: #721c24;
}

.stat-pill-warn {
    background: #fff3cd;
    color: #856404;
}

.stat-pill-muted {
    background: #e2e3e5;
    color: #383d41;
}

/* ── Email entry bar (compact) ───────────────────────────────── */
.email-bar {
    display: none;
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 0.75rem;
}

.email-bar.show-email-bar {
    display: block;
}

.email-bar-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.email-bar-label {
    font-weight: 600;
    white-space: nowrap;
    margin: 0;
}

.email-bar-input {
    flex: 1;
    max-width: 400px;
    padding: 0.4rem 0.75rem !important;
    font-size: 0.9rem;
}

.email-bar .help-text {
    margin-top: 0.35rem;
    margin-left: 5.5rem;
}

/* ── Filter bar inside card ──────────────────────────────────── */
.todos-filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.filter-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: normal;
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.9rem;
}

.filter-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.search-filter .form-control {
    width: 220px;
    padding: 0.4rem 0.75rem;
    font-size: 0.9rem;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-small {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

/* ── To-Do badges ────────────────────────────────────────────── */
.todo-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}

.status-open { background-color: #cce5ff; color: #004085; }
.status-progress { background-color: #fff3cd; color: #856404; }
.status-waiting { background-color: #e2e3e5; color: #383d41; }
.status-complete { background-color: #d4edda; color: #155724; }

.priority-critical { background-color: #f8d7da; color: #721c24; }
.priority-high { background-color: #ffe0b2; color: #e65100; }
.priority-normal { background-color: #e8f5e9; color: #2e7d32; }
.priority-low { background-color: #e3f2fd; color: #1565c0; }

/* ── Due date styling ────────────────────────────────────────── */
.due-date { font-weight: 600; white-space: nowrap; }
.due-date.overdue { color: #dc3545; }
.due-date.due-today { color: #e65100; }
.due-date.due-soon { color: #856404; }
.due-date.no-date { color: var(--secondary-text); font-weight: normal; font-style: italic; }

/* ── Table enhancements ──────────────────────────────────────── */
.title-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Sortable columns */
.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.5rem;
}

.sortable:hover { background-color: #dee2e6; }

.sortable::after {
    content: '';
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-top: 5px solid #adb5bd;
    margin-top: 3px;
}

.sortable.sort-asc::after {
    border-top: none;
    border-bottom: 5px solid var(--dark-color);
    margin-top: -3px;
}

.sortable.sort-desc::after {
    border-bottom: none;
    border-top: 5px solid var(--dark-color);
    margin-top: 3px;
}

/* ── Pagination ──────────────────────────────────────────────── */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 12px;
    padding: 10px;
}

#pageInfo { font-weight: 600; color: var(--text-color); }

/* ── Table action buttons ────────────────────────────────────── */
.btn-edit {
    padding: 5px 14px;
    font-size: 0.82em;
    background-color: #31C8F1;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    font-weight: 600;
}

.btn-edit:hover { background-color: #2ab3d9; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 40px; color: #6c757d; }
.empty-state h3 { margin-bottom: 10px; }

/* ── Modal form layout ───────────────────────────────────────── */
.modal-wide { max-width: 850px; }

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.form-group-grow { flex: 2 !important; }

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    color: #495057;
    font-size: 0.9rem;
}

.required { color: var(--danger-color); }

.modal-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.modal-at-link {
    margin-left: auto;
    font-size: 0.85rem;
}

/* ── Ticket List (shown when company selected) ───────────────── */
.ticket-list-section {
    margin: 0.75rem 0;
}
.ticket-list-section > label {
    font-weight: 600;
    font-size: 0.85rem;
    color: #374151;
    margin-bottom: 0.35rem;
    display: block;
}
.ticket-list {
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
}
.ticket-list-hint {
    font-weight: 400;
    font-size: 0.78rem;
    color: #6b7280;
}
.ticket-list-item {
    display: flex;
    gap: 0.5rem;
    padding: 0.35rem 0.65rem;
    border-bottom: 1px solid #e5e7eb;
    font-size: 0.82rem;
    line-height: 1.4;
    cursor: pointer;
    transition: background 0.15s;
}
.ticket-list-item:hover {
    background: #e8f0fe;
}
.ticket-list-item.selected {
    background: #d1fae5;
    border-left: 3px solid #10b981;
    font-weight: 600;
}
.ticket-list-item:last-child {
    border-bottom: none;
}
.ticket-list-number {
    font-weight: 600;
    color: #2563eb;
    white-space: nowrap;
}
.ticket-list-title {
    color: #374151;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ticket-list-loading,
.ticket-list-empty {
    padding: 0.65rem;
    font-size: 0.82rem;
    color: #6b7280;
    text-align: center;
}

/* ── Card spacing override for todos page ────────────────────── */
.todos-top-bar + .email-bar + .card,
.todos-top-bar + .card,
#todosCard {
    padding: 1rem 1.5rem;
}

/* ── Table hint ──────────────────────────────────────────────── */
.table-hint {
    text-align: center;
    font-size: 0.78rem;
    color: #9ca3af;
    margin-top: 0.35rem;
    font-style: italic;
}

/* ── Table row hover ─────────────────────────────────────────── */
#todosTable tbody tr:hover {
    background-color: #e8f4fd;
}

/* ── View Modal (read-only) ──────────────────────────────────── */
.view-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.view-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.view-field-full {
    margin-bottom: 1rem;
}

.view-field-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.view-field-value {
    font-size: 0.95rem;
    color: #111827;
    font-weight: 500;
}

.view-description {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.75rem;
    font-size: 0.9rem;
    color: #374151;
    white-space: pre-wrap;
    min-height: 60px;
    max-height: 200px;
    overflow-y: auto;
}

.completed-yes {
    color: #059669;
    font-weight: 600;
}

.completed-no {
    color: #6b7280;
    font-style: italic;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .todos-top-bar { flex-wrap: wrap; }
    .top-bar-spacer { display: none; }
    .todos-title { flex-shrink: 0; }
    .email-bar-inner { flex-direction: column; align-items: stretch; }
    .email-bar-input { max-width: 100%; }
    .email-bar .help-text { margin-left: 0; }
    .todos-filter-bar { flex-direction: column; align-items: flex-start; }
    .filter-controls { flex-direction: column; align-items: flex-start; }
    .search-filter .form-control { width: 100%; }
    .form-row { flex-direction: column; }
    .title-cell { max-width: 150px; }
    .pagination-controls { flex-direction: column; gap: 10px; }
    .stats-bar { justify-content: flex-start; }
    .view-grid { grid-template-columns: 1fr; }
}

.modal-medium { max-width: 720px; }

#todosTable tbody tr[data-todo-id] { cursor: pointer; }

.todo-view-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem 1.2rem;
}

.todo-view-item-full { grid-column: 1 / -1; }

.todo-view-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6b7280;
    margin-bottom: 0.2rem;
    font-weight: 700;
}

.todo-view-value {
    color: #1f2937;
    font-weight: 600;
    word-break: break-word;
}

.btn-danger,
.btn-complete {
    background: #dc3545;
    color: #fff;
    border: none;
}

.btn-danger:hover,
.btn-complete:hover {
    background: #bb2d3b;
}

.btn-complete {
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.82em;
    font-weight: 600;
}

.todo-action-buttons {
    display: flex;
    gap: 0.4rem;
}

/* ── Admin dropdown (inline in top bar) ────── */
.admin-resource-select {
    max-width: 180px;
    font-size: 0.78rem;
    padding: 0.2rem 0.4rem;
    height: auto;
}

/* ── Sync Companies button ────── */
.btn-sync-companies {
    background: #31C8F1;
    border: 1px solid #31C8F1;
    color: white;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, border-color 0.2s;
}

.btn-sync-companies:hover {
    background: #1db5de;
    border-color: #1db5de;
}

.btn-sync-companies:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
/* Assigned To column in admin mode */
.admin-assigned-col {
    white-space: nowrap;
}
.complete-help-text {
    margin-bottom: 0.75rem;
}

/* ── Priority + Status chip pickers on the task list ──────────────────────
   Each chip is an icon-only round button. Clicking it opens a dropdown
   menu of options where each option shows "<emoji> <word>" so users can
   still see what each colour means. The collapsed state shows only the
   symbol. */
.chip-cell { vertical-align: middle; }

.chip-picker {
    position: relative;
    display: inline-block;
}

.chip {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid transparent;
    border-radius: 999px;
    width: 28px;
    height: 28px;
    padding: 0;
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: filter 0.15s, box-shadow 0.15s, transform 0.05s;
}
.chip:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(49, 200, 241, 0.45);
}
.chip:hover { filter: brightness(0.95); }
.chip:active { transform: scale(0.95); }
.chip:disabled { opacity: 0.5; cursor: wait; }

.chip-empty {
    background-color: #f8f9fa;
    color: #6c757d;
    border-color: #d6dbe1;
    border-style: dashed;
    font-size: 0.85rem;
    font-weight: 500;
}

/* The dropdown menu that appears when a chip is clicked. */
.chip-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 50;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    background: #fff;
    border: 1px solid #d6dbe1;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    min-width: 140px;
    max-height: 320px;
    overflow-y: auto;
}
.chip-menu[hidden] { display: none; }
.chip-menu-item {
    padding: 6px 12px;
    font-size: 0.85rem;
    color: var(--text-color);
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
    user-select: none;
}
.chip-menu-item:hover { background-color: #eef2f7; }
.chip-menu-item[aria-selected="true"] {
    background-color: #e5edf6;
    font-weight: 600;
}
.chip-menu-empty { color: #6c757d; font-style: italic; }
.chip-menu-emoji { font-size: 1rem; line-height: 1; }

/* Priority — NOW (red), BAU (blue), PARKED (grey) */
.chip-priority-now {
    background-color: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}
.chip-priority-bau {
    background-color: #dbeafe;
    color: #1e40af;
    border-color: #93c5fd;
}
.chip-priority-parked {
    background-color: #e5e7eb;
    color: #374151;
    border-color: #d1d5db;
}

/* Status — Blocked (red), In progress (amber), Not started (grey), Complete (green) */
.chip-status-blocked {
    background-color: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}
.chip-status-in_progress {
    background-color: #fef3c7;
    color: #92400e;
    border-color: #fcd34d;
}
.chip-status-not_started {
    background-color: #e5e7eb;
    color: #374151;
    border-color: #d1d5db;
}
.chip-status-complete {
    background-color: #dcfce7;
    color: #166534;
    border-color: #86efac;
}

/* Visually dim rows the user has flagged "Complete" locally. */
tr.row-status-complete td:not(.chip-cell):not(.todo-action-buttons) {
    color: #9ca3af;
    text-decoration: line-through;
}
tr.row-status-complete .todo-badge { opacity: 0.6; }


/* ── Task notes timeline (Edit modal) ─────────────────────────────────────── */
.task-notes-section { margin-top: 18px; }
.task-notes-heading {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
}
.task-notes-timeline {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 8px;
    background-color: #f9fafb;
    margin-bottom: 10px;
}
.task-notes-empty {
    color: #9ca3af;
    font-style: italic;
    padding: 6px 4px;
}
.task-note {
    padding: 8px 10px;
    background-color: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    margin-bottom: 8px;
}
.task-note:last-child { margin-bottom: 0; }
.task-note-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: #6b7280;
    margin-bottom: 4px;
}
.task-note-who { font-weight: 600; color: #374151; }
.task-note-when { color: #9ca3af; }
.task-note-ticket-badge {
    margin-left: auto;
    background-color: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 0.72rem;
    font-weight: 600;
}
.task-note-text { white-space: pre-wrap; word-break: break-word; }
.task-notes-add textarea { margin-bottom: 8px; }
.task-notes-add-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.task-notes-ticket-toggle { font-size: 0.85rem; }

/* Outlook-origin (personal) task badge on the My Tasks list */
.todo-badge-outlook {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

/* Status toast (#status) — force readable colors. Success = white on green,
   error = white on red, info = white on blue. (Fixes green-text-on-green.) */
#status.status-message { color: #ffffff; font-weight: 600; }
#status.status-message.success { background: #28a745; color: #ffffff; }
#status.status-message.info    { background: #007bff; color: #ffffff; }
#status.status-message.error   { background: #dc3545; color: #ffffff; }

/* "open" deep-link to the source item (e.g. flagged email) on personal rows */
.task-open-link {
    font-size: 0.78rem;
    color: #1e40af;
    text-decoration: none;
    white-space: nowrap;
}
.task-open-link:hover { text-decoration: underline; }
