/* ═══════════════════════════════════════════════════════
   Task Sheet — HawkSoft CSV Task Export Viewer
   ═══════════════════════════════════════════════════════ */

/* ── Container ────────────────────────────────────────── */

.ts-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 24px 40px;
}

/* ── Header buttons ───────────────────────────────────── */

.ts-header-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    border-radius: 8px;
    background: var(--apple-blue);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s var(--transition-smooth);
}

.ts-header-btn:hover {
    background: var(--apple-blue-hover);
}

.ts-header-btn svg {
    flex-shrink: 0;
}

.ts-header-btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.ts-header-btn-outline:hover {
    background: var(--bg-widget-hover);
    color: var(--text);
}

/* Active/toggled state for Print All + Dedupe buttons */
.ts-header-btn-active {
    background: var(--apple-blue) !important;
    color: #fff !important;
    border-color: var(--apple-blue) !important;
}
.ts-header-btn-active:hover {
    background: var(--apple-blue-hover) !important;
    border-color: var(--apple-blue-hover) !important;
}

/* Dedupe count badge — shown in Task cell when duplicates are collapsed */
.ts-dedupe-count {
    display: inline-block;
    font-size: 0.72em;
    padding: 1px 6px;
    background: var(--bg-input);
    color: var(--text-secondary);
    border-radius: 10px;
    margin-left: 4px;
    vertical-align: middle;
    font-weight: 500;
}
body.dark-mode .ts-dedupe-count {
    background: #3a3a3c;
    color: rgba(235,235,245,0.75);
}

/* ── Drop zone ────────────────────────────────────────── */

.ts-drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 48px 24px;
    border: 2px dashed var(--border);
    border-radius: 16px;
    background: var(--bg-card);
    cursor: pointer;
    transition: border-color 0.2s var(--transition-smooth),
                box-shadow 0.2s var(--transition-smooth),
                background 0.2s var(--transition-smooth);
}

.ts-drop-zone:hover,
.ts-drop-zone.ts-drop-active {
    border-color: var(--apple-blue);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
    background: var(--bg-widget-hover);
}

.ts-drop-icon {
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.ts-drop-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.ts-drop-hint {
    font-size: 13px;
    color: var(--text-tertiary);
    margin: 0;
}

/* ── Agent filter bar ────────────────────────────────── */

.ts-agent-filter {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.ts-filter-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-right: 2px;
}

.ts-agent-chip {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1.5px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ts-agent-chip:hover {
    border-color: var(--apple-blue);
    color: var(--apple-blue);
}

.ts-agent-chip-on {
    background: var(--apple-blue);
    border-color: var(--apple-blue);
    color: #fff;
}

.ts-agent-chip-on:hover {
    background: var(--apple-blue-hover);
    border-color: var(--apple-blue-hover);
    color: #fff;
}

body.dark-mode .ts-agent-chip {
    background: #1C1C1E;
    border-color: #38383A;
    color: #98989D;
}

body.dark-mode .ts-agent-chip-on {
    background: #0A84FF;
    border-color: #0A84FF;
    color: #fff;
}

/* ── Secondary "add CSV" drop zone ───────────────────── */

.ts-add-drop-zone {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    margin-bottom: 12px;
    border: 1.5px dashed var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s var(--transition-smooth),
                color 0.2s var(--transition-smooth),
                background 0.2s var(--transition-smooth);
}

.ts-add-drop-zone:hover,
.ts-add-drop-zone.ts-drop-active {
    border-color: var(--apple-blue);
    color: var(--apple-blue);
    background: var(--bg-widget-hover);
}

body.dark-mode .ts-add-drop-zone {
    background: #1C1C1E;
    border-color: #38383A;
}

body.dark-mode .ts-add-drop-zone:hover,
body.dark-mode .ts-add-drop-zone.ts-drop-active {
    border-color: #0A84FF;
    color: #0A84FF;
    background: #2C2C2E;
}

@media print {
    .ts-add-drop-zone { display: none !important; }
}

/* ── Error ────────────────────────────────────────────── */

.ts-error {
    padding: 12px 16px;
    border-radius: 10px;
    background: rgba(255, 59, 48, 0.08);
    border: 1px solid rgba(255, 59, 48, 0.2);
    color: var(--danger);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 16px;
}

/* ── Meta bar ─────────────────────────────────────────── */

.ts-meta {
    padding: 12px 16px;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

.ts-meta-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.ts-meta-row + .ts-meta-row {
    margin-top: 4px;
}

.ts-meta-title {
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
}

.ts-meta-agency {
    font-size: 12px;
    color: var(--text-secondary);
}

.ts-meta-date {
    font-size: 13px;
    color: var(--text-secondary);
}

.ts-meta-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.ts-meta-overdue {
    font-size: 13px;
    font-weight: 600;
    color: var(--danger);
}

.ts-meta-clear {
    font-size: 13px;
    font-weight: 600;
    color: var(--success);
}

/* ── Table ────────────────────────────────────────────── */

.ts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.ts-table thead {
    background: var(--bg-input);
}

.ts-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.ts-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text);
    vertical-align: top;
}

.ts-table tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.015);
}

.ts-table tbody tr:hover {
    background: var(--bg-widget-hover);
}

/* Column widths */
.ts-col-notes { min-width: 180px; }
.ts-cell-date { white-space: nowrap; }
.ts-cell-client { max-width: 180px; }
.ts-cell-category { max-width: 120px; }
.ts-cell-task { max-width: 260px; }
.ts-cell-carrier { max-width: 110px; }
.ts-cell-status { white-space: nowrap; max-width: 110px; }
.ts-cell-policy-dates { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.ts-cell-notes { min-width: 180px; }

/* Notes column — screen placeholder hint (kept for compat) */
.ts-notes-placeholder {
    font-size: 11px;
    color: var(--text-tertiary);
    font-style: italic;
    opacity: 0.5;
    user-select: none;
}

/* ── Done checkbox ────────────────────────────────────── */
.ts-col-check,
.ts-cell-check {
    width: 38px;
    min-width: 38px;
    text-align: center;
    padding: 0 6px;
    vertical-align: middle;
}

.ts-task-check {
    width: 17px;
    height: 17px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--success);
    vertical-align: middle;
    display: block;
    margin: auto;
}

/* Checked rows: dim everything + strike the task text */
.ts-table tbody tr:has(.ts-task-check:checked) td {
    opacity: 0.38;
    transition: opacity 0.18s;
}

.ts-table tbody tr:has(.ts-task-check:checked) .ts-cell-task {
    text-decoration: line-through;
    text-decoration-color: var(--text-secondary);
}

.ts-table tbody tr:has(.ts-task-check:checked) {
    background: rgba(52, 199, 89, 0.04) !important;
}

/* ── Inline notes (contenteditable) ──────────────────── */
.ts-notes-edit {
    min-height: 1em;
    outline: none;
    border-radius: 4px;
    padding: 2px 4px;
    margin: -2px -4px;
    transition: background 0.15s, box-shadow 0.15s;
    line-height: 1.5;
    word-break: break-word;
}

.ts-notes-edit:hover {
    background: var(--bg-input);
}

.ts-notes-edit:focus {
    background: var(--bg-input);
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.25);
}

/* CSS placeholder via :empty + ::before for contenteditable */
.ts-notes-edit:not(:focus):empty::before {
    content: attr(data-placeholder);
    color: var(--text-tertiary);
    font-style: italic;
    opacity: 0.5;
    pointer-events: none;
    display: block;
}

body.dark-mode .ts-notes-edit:focus {
    box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.3);
}

/* ── Overdue row ──────────────────────────────────────── */

.ts-row-overdue {
    background: rgba(255, 59, 48, 0.05) !important;
}

.ts-row-overdue:hover {
    background: rgba(255, 59, 48, 0.08) !important;
}

.ts-overdue-inline {
    color: var(--danger);
    font-size: 12px;
    margin-left: 4px;
}

/* ── Priority badges ──────────────────────────────────── */

.ts-priority-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.ts-priority-critical {
    background: #fee2e2;
    color: #991b1b;
}

.ts-priority-high {
    background: #ffedd5;
    color: #9a3412;
}

.ts-priority-medium {
    background: #fef3c7;
    color: #92400e;
}

.ts-priority-low {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-tertiary);
}

/* ═══════════════════════════════════════════════════════
   DARK MODE
   ═══════════════════════════════════════════════════════ */

body.dark-mode .ts-drop-zone {
    background: #1C1C1E;
    border-color: #38383A;
}

body.dark-mode .ts-drop-zone:hover,
body.dark-mode .ts-drop-zone.ts-drop-active {
    border-color: #0A84FF;
    box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.2);
    background: #2C2C2E;
}

body.dark-mode .ts-error {
    background: rgba(255, 69, 58, 0.12);
    border-color: rgba(255, 69, 58, 0.25);
}

body.dark-mode .ts-meta {
    background: #1C1C1E;
    border-color: #38383A;
}

body.dark-mode .ts-table {
    background: #1C1C1E;
    border-color: #38383A;
}

body.dark-mode .ts-table thead {
    background: #2C2C2E;
}

body.dark-mode .ts-table th {
    border-bottom-color: #38383A;
}

body.dark-mode .ts-table td {
    border-bottom-color: #2C2C2E;
}

body.dark-mode .ts-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

body.dark-mode .ts-table tbody tr:hover {
    background: #2C2C2E;
}

body.dark-mode .ts-row-overdue {
    background: rgba(255, 69, 58, 0.1) !important;
}

body.dark-mode .ts-row-overdue:hover {
    background: rgba(255, 69, 58, 0.15) !important;
}

body.dark-mode .ts-priority-critical {
    background: rgba(255, 69, 58, 0.18);
    color: #FF6961;
}

body.dark-mode .ts-priority-high {
    background: rgba(255, 159, 10, 0.18);
    color: #FF9F0A;
}

body.dark-mode .ts-priority-medium {
    background: rgba(255, 214, 10, 0.15);
    color: #FFD60A;
}

body.dark-mode .ts-priority-low {
    background: rgba(255, 255, 255, 0.05);
    color: #8E8E93;
}

body.dark-mode .ts-header-btn-outline {
    border-color: #38383A;
    color: #98989D;
}

body.dark-mode .ts-header-btn-outline:hover {
    background: #2C2C2E;
    color: #FFFFFF;
}

/* ═══════════════════════════════════════════════════════
   PRINT STYLES — handwriting-friendly layout
   Generous row height, ruled notes column, clear borders
   ═══════════════════════════════════════════════════════ */

@media print {
    @page {
        size: letter landscape;
        margin: 0.4in 0.35in 0.35in;
    }

    /* Hide all non-content chrome */
    body > *:not(.app-shell),
    .sidebar,
    .mobile-bottom-nav,
    #mobileBottomNav,
    #syncIndicator,
    #toast,
    .no-print,
    .header-top,
    .ts-drop-zone,
    .ts-error {
        display: none !important;
    }

    /* Flatten layout so only the table shows */
    html, body {
        background: #fff !important;
    }

    .app-shell,
    .app-content,
    .app-main,
    .plugin-viewport,
    .plugin-container {
        overflow: visible !important;
        position: static !important;
        width: 100% !important;
        max-width: none !important;
        height: auto !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
    }

    .ts-container {
        max-width: none;
        padding: 0;
        background: #fff !important;
        overflow: visible !important;
        height: auto !important;
    }

    /* ── Print header ─────────────────────────────── */
    .ts-meta {
        display: block;
        background: none !important;
        border: none !important;
        padding: 0 0 5px;
        margin-bottom: 6px;
        border-bottom: 1.5pt solid #000;
    }

    .ts-meta-row {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        line-height: 1.3;
    }

    .ts-meta-sub-row {
        margin-top: 1px;
    }

    /* "[Name]'s Tasks" — main title */
    .ts-meta-title {
        font-size: 13pt;
        font-weight: 700;
        color: #000;
    }

    /* Date — right-aligned on the title row */
    .ts-meta-date {
        font-size: 7.5pt;
        color: #444;
    }

    /* Agency name — small sub-line */
    .ts-meta-agency {
        font-size: 6.5pt;
        color: #666;
        font-weight: 400;
    }

    /* Task count + overdue count */
    .ts-meta-count {
        font-size: 6.5pt;
        color: #333;
        font-weight: 600;
    }

    .ts-meta-overdue {
        font-size: 6.5pt;
        color: #000;
        font-weight: 700;
    }

    /* Hide screen-only elements */
    .ts-meta-sep,
    .ts-meta-clear,
    .ts-notes-placeholder,
    .ts-notes-edit::before {
        display: none !important;
    }

    /* ── Table ────────────────────────────────────── */
    .ts-output {
        overflow: visible !important;
    }

    /* Ensure column headers repeat on every print page */
    thead {
        display: table-header-group;
    }

    .ts-table {
        width: 100%;
        font-size: 7.5pt;
        line-height: 1.35;
        border-collapse: collapse;
        border-radius: 0;
        background: #fff;
        table-layout: fixed;
    }

    /* Column widths set via inline <col> in task-sheet.js (8 columns always) */

    /* Header — white background, bold bottom rule, no toner fill */
    .ts-table thead tr {
        background: #fff !important;
    }

    .ts-table th {
        font-size: 6pt;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        padding: 5px 6px 4px;
        color: #000 !important;
        border-bottom: 1.5pt solid #000;
        text-align: left;
    }

    .ts-table td {
        padding: 11px 6px;
        color: #111;
        border-bottom: 0.5pt solid #ddd;
        vertical-align: middle;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Single-line columns — nowrap, clip with ellipsis */
    .ts-cell-date,
    .ts-cell-client,
    .ts-cell-carrier,
    .ts-cell-status {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Overdue marker — force inline so ⚠ stays on the same line as the date */
    .ts-overdue-inline {
        display: inline !important;
        white-space: nowrap;
    }

    /* Task — no height constraint, let rows size naturally */
    .ts-cell-task {
        overflow: hidden;
    }

    /* All rows white — no alternating fill, no shading */
    .ts-table tbody tr,
    .ts-table tbody tr:nth-child(even),
    .ts-row-overdue,
    .ts-row-overdue td {
        background: #fff !important;
        background-color: #fff !important;
    }

    .ts-table tbody tr:hover {
        background: #fff !important;
    }

    /* Overdue rows — left accent rule only, no fill */
    .ts-row-overdue td:first-child {
        border-left: 3pt solid #000;
    }

    /* Overdue inline marker */
    .ts-overdue-inline {
        font-weight: 700;
        color: #000;
    }

    /* Priority badges — outline style, no fill, toner-friendly */
    .ts-priority-badge {
        display: inline-block;
        padding: 1px 5px;
        border-radius: 3px;
        font-size: 6pt;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        background: none !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .ts-priority-critical {
        border: 1.5pt solid #000 !important;
        color: #000 !important;
    }
    .ts-priority-high {
        border: 1pt solid #333 !important;
        color: #333 !important;
    }
    .ts-priority-medium {
        border: 1pt solid #777 !important;
        color: #777 !important;
    }
    .ts-priority-low {
        border: 1pt solid #bbb !important;
        color: #bbb !important;
    }

    /* Agent Notes column — ruled lines for handwriting */
    .ts-cell-notes {
        border-left: 0.75pt solid #bbb;
        padding: 11px 6px;
        background-image: repeating-linear-gradient(
            transparent,
            transparent 18px,
            #e0e0e0 18px,
            #e0e0e0 19px
        );
        background-position: 0 11px;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Policy date labels ("Eff:", "Exp:") */
    .ts-policy-label {
        font-size: 80%;
        font-weight: 600;
        color: #555;
    }

    /* Policy dates — compact */
    .ts-cell-policy-dates {
        font-size: 6.5pt;
        white-space: normal;
        word-break: break-word;
    }

    /* Keep each row together on the page */
    .ts-table tr {
        page-break-inside: avoid;
    }

    /* Single-page default: hide rows beyond the first 20 (lower-priority tasks).
       Tasks are pre-sorted overdue → priority → due date, so the most urgent
       items are always at the top. */
    .ts-table tbody tr:nth-child(n+21) {
        display: none !important;
    }

    /* Override the 20-row cap when agent chose "Print All" */
    .ts-show-all-rows .ts-table tbody tr:nth-child(n+21) {
        display: table-row !important;
    }

    /* Dedupe count badge — compact grey text in print */
    .ts-dedupe-count {
        font-size: 6pt;
        color: #666;
        background: none;
        border: none;
        padding: 0;
    }

    /* Done checkbox — preserve checked/unchecked visual state in print */
    .ts-task-check {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .ts-cell-check {
        padding: 4px 3px;
        vertical-align: middle;
    }

    /* Checked rows in print — strike + grey */
    .ts-table tbody tr:has(.ts-task-check:checked) .ts-cell-task {
        text-decoration: line-through;
        color: #999;
    }

    .ts-table tbody tr:has(.ts-task-check:checked) td {
        color: #999;
    }

    /* Inline notes — strip contenteditable chrome for clean print */
    .ts-notes-edit {
        min-height: auto;
        padding: 0;
        margin: 0;
        background: none !important;
        box-shadow: none !important;
    }

    /* Footer rule */
    .ts-table tfoot td {
        border-top: 1pt solid #999;
        font-size: 6.5pt;
        color: #666;
        padding: 4px 6px;
    }
}

/* ── Overflow notice (tfoot cell inside the table) ───── */

.ts-overflow-cell {
    padding: 6px 10px;
    font-size: 12px;
    font-style: italic;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    border-bottom: none;
}

body.dark-mode .ts-overflow-cell {
    color: #8E8E93;
}

/* ═══════════════════════════════════════════════════════
   TEAM MODE — per-agent sections
   ═══════════════════════════════════════════════════════ */

.ts-agent-section {
    margin-bottom: 40px;
}

.ts-agent-section .ts-meta {
    margin-bottom: 12px;
}

/* Screen: subtle divider between agents */
.ts-agent-section-break {
    border-top: 2px dashed var(--border);
    padding-top: 32px;
    margin-top: 8px;
}

@media print {
    /* Every agent section gets its own page — but NOT the last one
       (trailing page-break causes PDF to cut off the final agent) */
    .ts-agent-section {
        display: block;
        page-break-after: always;
        break-after: page;
    }

    .ts-agent-section-last {
        page-break-after: auto !important;
        break-after: auto !important;
    }

    /* The -break variant just removes screen-only styles */
    .ts-agent-section-break {
        border-top: none;
        padding-top: 0;
        margin-top: 0;
    }

    /* Per-agent meta inside team sections uses the same print styles as .ts-meta */
    .ts-agent-section .ts-meta {
        display: block;
        background: none;
        border: none;
        padding: 0 0 5px;
        margin-bottom: 6px;
        border-bottom: 1.5pt solid #000;
    }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */

@media (max-width: 960px) {
    .ts-output {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 600px) {
    .ts-container {
        padding: 12px 12px 24px;
    }

    .ts-drop-zone {
        padding: 32px 16px;
    }
}
