:root { color-scheme: light; }
* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #f4f6f9;
    color: #1f2937;
}

.page {
    max-width: 1160px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

/* The task table uses the whole screen width with small side margins. */
.page-wide {
    max-width: none;
    margin: 0;
    padding: 16px 20px 48px;
}

#tasks-table { overflow-x: auto; }

/* Task table: columns are as wide as their content; the screen is only the upper bound. */
.tasks-table {
    width: auto;
    max-width: 100%;
}
.tasks-table th,
.tasks-table td { white-space: nowrap; }
.tasks-table td { vertical-align: middle; }
.task-type-link {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    font-weight: 500;
    color: #0d6efd;
    text-decoration: none;
    cursor: pointer;
}
/* Only the task name is underlined: the icon and the gap before it stay clean. */
.task-type-name { text-decoration: underline; }
.task-type-icon {
    display: inline-block;
    color: #6b7280;
    font-family: "Segoe UI Symbol", "DejaVu Sans", sans-serif;
    font-weight: 400;
}
.sort-icons {
    font-size: 11px;
    letter-spacing: 1px;
    margin-left: 2px;
}

/* Checkbox is a real input; the flag is its visible label */
.task-check {
    position: relative;
    display: inline-flex;
    cursor: pointer;
}
.task-check input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}
.task-flag {
    font-family: "Segoe UI Symbol", "DejaVu Sans", sans-serif;
    font-size: 22px;
    line-height: 1;
    color: #9ca3af;
}
.task-check input:checked + .task-flag { color: #2563eb; }
.task-check input:focus-visible + .task-flag {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Loading skeletons.
   The task list placeholder has no header and no cell borders: each row is one
   long bar. Its width matches the loaded table on a typical screen so the list
   does not change width when the data arrives; narrow screens keep 100%. */
.tasks-skeleton {
    width: 100%;
    /* Approximate width of the loaded table; the script refines it after the first swap. */
    max-width: var(--tasks-table-width, 780px);
    padding: 4px 8px;
    background: #fff;
}
.tasks-skeleton .skeleton-row {
    /* Same height as a Bootstrap table row: 14px bar + two 13px paddings. */
    padding: 13px 0;
}
.skeleton-row span {
    display: block;
    width: 100%;
    min-width: 56px; /* visible bar in a narrow panel block */
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, #e5e7eb, #f3f4f6, #e5e7eb);
    animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
    0% { opacity: .55; }
    50% { opacity: 1; }
    100% { opacity: .55; }
}

/* Right-side panel: half of the screen, full width on narrow displays.
   On a wide screen the panel itself does not scroll: the header, the call details
   and the player stay in place and only the transcript or the letter scrolls.
   On narrow displays the panel scrolls again, but the transcript keeps a capped
   scroll area of its own, so reading it still does not move the player. */
dialog.task-panel {
    margin: 0 0 0 auto;
    height: 100vh;
    max-height: 100vh;
    width: 50vw;
    max-width: 100vw;
    border: 0;
    padding: 0;
    background: #fff;
    overflow: hidden;
}
dialog.task-panel[open] {
    display: flex;
    flex-direction: column;
}
@media (max-width: 900px) {
    dialog.task-panel {
        width: 100vw;
        min-width: 0;
        overflow-y: auto;
    }
    dialog.task-panel[open] { display: block; }
    .task-panel-column-main .transcript,
    .task-panel-column-main .letter-body { max-height: 55vh; }
}
dialog.task-panel::backdrop { background: rgba(15, 23, 42, .35); }
/* The deal link and the close button share the first row of the panel. The row
   sticks to the top while the body scrolls in a short window, so the close
   button stays reachable. */
.task-panel-top {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
}
.task-panel-top a {
    min-width: 0;
    overflow-wrap: anywhere;
}
.task-panel-close {
    margin-left: auto;
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: #374151;
    font-size: 28px;
    line-height: 1;
    padding: 0 4px;
    cursor: pointer;
}
.task-panel-close:hover { color: #111827; }

/* Panel content: the recording/transcript or the letter takes two thirds,
   the archive and Bitrix24 results take one third. On narrow displays the
   columns stack in reading order. The panel body fills the dialog height so
   the call card can give the remaining space to the transcript. */
#panel-body,
.task-panel-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}
/* A short window leaves no room for the card itself: the body scrolls then,
   while the transcript keeps a readable minimum height. */
#panel-body { overflow-y: auto; }
.task-panel-columns {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
}
.task-panel-column { min-width: 0; min-height: 0; }
.task-panel-column-main { display: flex; flex-direction: column; }
/* Search results scroll on their own; the panel itself does not scroll. */
.task-panel-column-search {
    overflow-y: auto;
    overscroll-behavior: contain;
}
@media (max-width: 900px) {
    .task-panel-columns { grid-template-columns: 1fr; }
    #panel-body,
    .task-panel-body { display: block; }
}

/* Panel blocks: the recording/letter and the two search results are visually
   separate. The link body is replaced by the block endpoint after it loads. */
.panel-block {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fff;
}
.panel-block:last-child { margin-bottom: 0; }
.panel-block-title { margin: 0 0 8px; }
.panel-block-body { min-height: 20px; }
/* Call facts: phone and line on the left, clinic and call time on the right.
   The talk duration is deliberately not shown. */
.panel-call-facts {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0 16px;
}
.panel-call-facts-col {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    margin: 0;
    align-content: start;
}
.panel-call-facts-col dt {
    color: #4b5563;
    font-weight: 500;
}
.panel-call-facts-col dd {
    margin: 0 0 8px;
    overflow-wrap: anywhere;
}
.panel-call-facts-col dd:last-child { margin-bottom: 0; }
@media (max-width: 600px) {
    .panel-call-facts { grid-template-columns: 1fr; gap: 8px 16px; }
}
/* The call or letter card passes the free height to its scrollable part. */
.panel-block-main {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}
.panel-links {
    list-style: none;
    margin: 0;
    padding: 0;
}
.panel-links li {
    padding: 6px 0;
    border-top: 1px solid #f1f5f9;
    overflow-wrap: anywhere;
}
.panel-links li:first-child { border-top: 0; padding-top: 0; }
.panel-links li:last-child { padding-bottom: 0; }
.panel-links-type {
    color: #6b7280;
    font-size: 12px;
    margin-right: 6px;
}
.panel-links-count { color: #6b7280; font-size: 12px; margin: 8px 0 0; }
.panel-links-warning { color: #92400e; font-size: 12px; margin: 8px 0 0; }
.panel-links-empty { color: #6b7280; margin: 0; }
.panel-links-error { color: #b91c1c; margin: 0; }
.panel-links-retry { color: inherit; }

/* Website request text: raw line breaks are rendered by pre-line, so the PHP side
   must not turn them into <br> as well. A long letter scrolls inside the card. */
.letter-body {
    white-space: pre-line;
    overflow-wrap: anywhere;
}
.task-panel-column-main .letter-body {
    flex: 1 1 auto;
    min-height: 8rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Recording player and speed. The native control bar is drawn by the browser and
   cannot host a custom button, so a compact stepper sits beside the player and
   drives its playbackRate. */
.recording-player {
    display: flex;
    align-items: center;
    gap: 8px;
}
.recording-audio {
    flex: 1 1 auto;
    min-width: 0;
}
.recording-speed {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
}
.recording-speed-step {
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #1f2937;
    font: inherit;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}
.recording-speed-step:hover:not(:disabled) { background: #f3f4f6; }
.recording-speed-step:disabled { opacity: .4; cursor: default; }
.recording-speed-step:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}
.recording-speed-value {
    min-width: 36px;
    text-align: center;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    color: #374151;
}

/* Transcript: the role colors a pill around the timecode; the words "operator"
   and "client" are not printed. The list has its own scrollbar, so reading a
   long conversation never moves the player above it. */
.task-panel-column-main .transcript {
    flex: 1 1 auto;
    min-height: 8rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.task-panel-column-main .transcript:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}
.transcript-list {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
}
.transcript-utterance {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 10px;
    align-items: start;
    padding: 8px 0;
    border-bottom: 1px solid #f1f5f9;
}
.transcript-utterance:last-child { border-bottom: 0; }
.transcript-time {
    display: block;
    width: 100%;
    padding: 3px 6px;
    border: 0;
    border-radius: 999px;
    background: #e5e7eb;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.3;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    color: #374151;
}
.transcript-operator .transcript-time { background: #dbeafe; color: #1d4ed8; }
.transcript-client .transcript-time { background: #d1fae5; color: #047857; }
.transcript-speaker .transcript-time { background: #ede9fe; color: #7c3aed; }
.transcript-time:hover { filter: brightness(.95); }
.transcript-time:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}
.transcript-text { min-width: 0; overflow-wrap: anywhere; }
.transcript-state { color: #6b7280; margin: 12px 0 0; }
@media (max-width: 600px) {
    .transcript-utterance { grid-template-columns: 1fr; gap: 4px; }
    .transcript-time { justify-self: start; width: auto; }
}

/* Login page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 380px;
    padding: 32px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 8px 30px rgba(15, 23, 42, .08);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .hint { margin: 0 0 24px; color: #6b7280; font-size: 14px; }
