/* OmniDesk — сайт оператора. Палитра как у OmniStat (popup.css). */
:root {
    --bg: #f8f9fa;
    --panel: #ffffff;
    --line: #e5e7eb;
    --ink: #111827;
    --ink-2: #374151;
    --muted: #6b7280;
    --accent: #2563eb;
    --accent-weak: #eff6ff;
    --ok: #10b981;
    --warn: #b45309;
    --warn-weak: #fffbeb;
    --bad: #ef4444;
    --bad-weak: #fef2f2;
    --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
}
button { font: inherit; cursor: pointer; border: none; border-radius: 6px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1.2em; }
[hidden] { display: none !important; }

/* ---------- Вход ---------- */
.login { height: 100%; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 32px 40px;
              text-align: center; min-width: 320px; }
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card p { margin: 0 0 24px; }
#google-button { display: flex; justify-content: center; min-height: 44px; }

/* ---------- Каркас ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel);
          border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 16px; }
.spacer { flex: 1; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.pill.ok { background: #ecfdf5; color: #047857; }
.pill.bad { background: var(--bad-weak); color: var(--bad); }
.btn-link { background: none; color: var(--accent); padding: 4px 6px; }
.layout { flex: 1; display: grid; grid-template-columns: minmax(300px, 380px) 1fr; min-height: 0; }

/* ---------- Входящие ---------- */
.inbox { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { background: none; color: var(--muted); padding: 6px 10px; font-size: 13px; }
.tabs button.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent);
         color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.badge:empty { display: none; }
.inbox-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.inbox-item { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.inbox-item:hover { background: var(--bg); }
.inbox-item.active { background: var(--accent-weak); }
.inbox-item .row1 { display: flex; justify-content: space-between; gap: 8px; }
.inbox-item .buyer { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-item .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.inbox-item .when.due-soon { color: var(--bad); font-weight: 600; }
.inbox-item .subject { font-size: 12px; color: var(--ink-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-item .preview { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden;
                       display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.inbox-item .problem { color: var(--bad); font-size: 11px; font-weight: 600; margin-top: 3px; }

/* ---------- Ветка ---------- */
.conversation { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.placeholder { margin: auto; }
.conv-head { padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
             display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.conv-head h2 { margin: 0; font-size: 16px; }
.conv-head .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.conv-head .actions { margin-left: auto; display: flex; gap: 6px; }
.btn { background: var(--panel); border: 1px solid #d1d5db; color: var(--ink-2); padding: 6px 12px; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; padding: 8px 18px; font-weight: 600; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #d1d5db; cursor: not-allowed; }
.due { font-size: 12px; padding: 3px 8px; border-radius: 6px; background: var(--warn-weak); color: var(--warn); }
.due.late { background: var(--bad-weak); color: var(--bad); }
.conv-body { flex: 1; display: grid; grid-template-columns: 1fr 280px; min-height: 0; }
.thread { overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 75%; padding: 10px 12px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; }
.msg.buyer { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.seller { align-self: flex-end; background: var(--accent-weak); border: 1px solid #dbeafe; }
.msg.system { align-self: center; background: none; color: var(--muted); font-size: 12px; }
.msg .msg-meta { font-size: 11px; color: var(--muted); margin-top: 6px; display: flex; gap: 8px; justify-content: space-between; }
.msg .delivery.failed, .msg .delivery.unknown { color: var(--bad); font-weight: 600; }
.msg .delivery.delivered { color: var(--ok); }
.side { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 14px; font-size: 13px; }
.side h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; }
.side h3:first-child { margin-top: 0; }
.side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; }
.side dt { color: var(--muted); }
.side dd { margin: 0; word-break: break-word; }

/* ---------- Ответ ---------- */
.reply { border-top: 1px solid var(--line); background: var(--panel); padding: 12px 18px; }
.reply-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.reply-tools select { padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px; font: inherit; max-width: 360px; }
.suggest { font-size: 12px; color: var(--accent); }
.reply textarea { width: 100%; min-height: 110px; resize: vertical; padding: 10px; border: 1px solid #d1d5db;
                  border-radius: var(--radius); font: inherit; line-height: 1.45; }
.reply textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37, 99, 235, .12); }
.reply-bottom { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.reply-bottom .warn { color: var(--warn); font-size: 12px; }

/* ---------- Режим отправки ---------- */
.mode-banner { display: flex; align-items: center; gap: 12px; padding: 8px 16px; font-size: 13px;
               background: var(--warn-weak); color: var(--warn); border-bottom: 1px solid #fde68a; }
.mode-banner.live { background: #ecfdf5; color: #047857; border-bottom-color: #a7f3d0; }
.mode-banner b { font-weight: 700; }
.mode-banner button { margin-left: auto; }

/* ---------- Черновики и пробные ответы ---------- */
.msg.seller.draft { background: #fff; border: 1px dashed var(--accent); }
.msg.seller.dry_run { background: var(--warn-weak); border: 1px dashed #f59e0b; }
.msg .delivery.draft, .msg .delivery.dry_run { color: var(--warn); font-weight: 600; }
.draft-actions { display: flex; gap: 6px; margin-top: 8px; }
.draft-actions .btn-primary { padding: 5px 12px; font-size: 13px; }
.inbox-item .draft-note { color: var(--accent); font-size: 11px; font-weight: 600; margin-top: 3px; }

/* ---------- Окно подтверждения ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); display: flex; align-items: center;
                  justify-content: center; padding: 16px; z-index: 20; }
.modal { background: var(--panel); border-radius: 12px; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 20px; }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.confirm-mode { margin: 0 0 12px; padding: 8px 10px; border-radius: 6px; font-size: 13px; background: var(--warn-weak); color: var(--warn); }
.confirm-mode.live { background: var(--bad-weak); color: var(--bad); font-weight: 600; }
.confirm-to { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px; font-size: 13px; }
.confirm-to dt { color: var(--muted); }
.confirm-to dd { margin: 0; }
.confirm-text { white-space: pre-wrap; word-wrap: break-word; border: 1px solid var(--line); border-radius: 8px;
                padding: 10px 12px; background: var(--bg); max-height: 40vh; overflow: auto; line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- Переключатель разделов ---------- */
.views { display: flex; gap: 4px; }
.views button { background: none; color: var(--muted); padding: 6px 10px; font-size: 13px; }
.views button.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

/* ---------- Возвраты (как Manage Returns) ---------- */
.returns-view { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.rhead { display: flex; align-items: center; gap: 10px; padding: 12px 16px 6px; flex-wrap: wrap; }
.rhead h2 { margin: 0; font-size: 20px; }
.rlast { display: inline-flex; gap: 4px; align-items: center; }
.rlast input { width: 70px; padding: 6px; border: 1px solid #d1d5db; border-radius: 6px; font: inherit; }
.rfilters { display: flex; gap: 8px; align-items: center; padding: 8px 16px 12px; flex-wrap: wrap;
            border-bottom: 1px solid var(--line); }
.rfilters select, .rfilters input[type=search] { padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px; font: inherit; background: #fff; }
.rsearch { display: inline-flex; }
.rsearch select { border-radius: 6px 0 0 6px; border-right: none; }
.rsearch input { border-radius: 0 6px 6px 0 !important; width: 200px; }
.rdrop { position: relative; }
.rdrop summary { list-style: none; cursor: pointer; padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; }
.rdrop summary::-webkit-details-marker { display: none; }
.rdrop summary::after { content: ' ▾'; color: var(--muted); }
.rmenu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 5; min-width: 180px; display: flex; flex-direction: column;
         background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 4px 0; box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.rmenu label { display: flex; gap: 6px; align-items: center; padding: 6px 12px; white-space: nowrap; cursor: pointer; }
.rmenu label:hover { background: var(--bg); }
.rtable-wrap { flex: 1; overflow: auto; }
.rtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.rtable th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 600; padding: 8px 10px;
             border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
.rtable th small { font-weight: 400; color: var(--muted); }
.rtable td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rrow { cursor: pointer; }
.rrow:hover { background: var(--bg); }
.rrow.open { background: var(--accent-weak); }
.rrow.has-draft td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.rorder { color: var(--accent); font-weight: 600; text-decoration: none; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rprime { color: #0ea5e9; font-weight: 700; font-style: italic; font-size: 12px; }
.rproduct { max-width: 280px; }
.rtitle { color: var(--accent); }
.rreason { max-width: 260px; }
.rlate { color: var(--bad) !important; font-weight: 600; }
.rnote { font-size: 11px; color: var(--muted); }
.rstate { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--ink-2); white-space: nowrap; }
.rstate.rs-PendingRefund { background: #be123c; color: #fff; }
.rstate.rs-Completed { background: #e5e7eb; }
.rletter { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.rletter.rl-draft { background: var(--accent); color: #fff; }
.rletter.rl-sent { background: #ecfdf5; color: #047857; }
.rletter.rl-dry_run { background: var(--warn-weak); color: var(--warn); }
.rletter.rl-failed { background: var(--bad-weak); color: var(--bad); }
.rletter.rl-new, .rletter.rl-waiting_tracking { background: var(--accent-weak); color: var(--accent); }
.ractions { display: flex; gap: 6px; flex-wrap: wrap; }
.ractions .btn-primary { padding: 6px 12px; }
.rdetails-row td { background: #fafbff; }
.rdetails { display: flex; flex-direction: column; gap: 10px; max-width: 900px; }
.rdetails dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.rdetails dt { color: var(--muted); }
.rdetails dd { margin: 0; word-break: break-word; }
.rdraft { width: 100%; padding: 10px; border: 1px solid #d1d5db; border-radius: var(--radius); font: inherit; line-height: 1.45; resize: vertical; }
.rpager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 8px 16px; border-top: 1px solid var(--line); }
@media (max-width: 700px) {
    .views button { padding: 6px 6px; }
    .rsearch input { width: 130px; }
}

/* ---------- Уведомление ---------- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
         padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 10; max-width: 90vw; }
.toast.error { background: var(--bad); }

/* ---------- Узкие экраны ---------- */
.btn-side { display: none; }
@media (max-width: 900px) {
    .conv-body { grid-template-columns: 1fr; }
    .btn-side { display: inline-block; }
    /* Заказ и возврат — по кнопке, чтобы переписка получала всё место */
    .side { display: none; border-left: none; border-bottom: 1px solid var(--line); max-height: 45vh; order: -1; }
    .conv-body.show-side .side { display: block; }
    .conv-body { display: flex; flex-direction: column; }
    .conv-body > :not(.side) { flex: 1; min-height: 0; }
    .reply textarea { min-height: 80px; }
}
@media (max-width: 700px) {
    #operator-email { display: none; }
    .topbar { gap: 8px; }
    .layout { grid-template-columns: 1fr; }
    .inbox { border-right: none; }
    .layout.has-conversation .inbox { display: none; }
    .layout:not(.has-conversation) .conversation { display: none; }
    .msg { max-width: 92%; }
}
