:root {
    --bg: #f5f6f8;
    --surface: #fff;
    --text: #1f2933;
    --muted: #697386;
    --line: #dde2ea;
    --red: #e91d25;
    --red-dark: #b9151c;
    --red-soft: #fde8e9;
    --blue: #2563eb;
    --blue-soft: #e8f0ff;
    --green: #15803d;
    --green-soft: #e9f8ee;
    --amber: #b45309;
    --amber-soft: #fff4d6;
    --body: "Poppins", system-ui, sans-serif;
    --display: "Roboto Condensed", "Arial Narrow", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--body); }
button, input, textarea { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.query-app { min-height: 100vh; }
.query-app-header {
    align-items: center;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 12px;
    min-height: 72px;
    padding: 12px 20px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.query-app-brand {
    align-items: center;
    background: var(--red);
    border-radius: 999px;
    color: #fff;
    display: flex;
    flex: 0 0 auto;
    font-family: var(--display);
    font-size: 14px;
    font-weight: 800;
    height: 42px;
    justify-content: center;
    width: 42px;
}
.query-app-brand svg {
    fill: none;
    height: 24px;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
    width: 24px;
}
.query-app-heading { flex: 1; min-width: 0; }
.query-app-heading strong { display: block; font-family: var(--display); font-size: 20px; letter-spacing: .025em; }
.query-app-heading span, .query-app-user span { color: var(--muted); display: block; font-size: 11px; }
.query-app-user { flex: 0 1 auto; min-width: 0; text-align: right; }
.query-app-user strong { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.query-app-user .query-preview-label {
    color: var(--blue);
    font-family: var(--display);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .045em;
    margin-top: 2px;
}
.query-app-close {
    align-items: center;
    background: #f4f6f8;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    display: inline-flex;
    flex: 0 0 auto;
    font-family: var(--body);
    font-size: 22px;
    height: 38px;
    justify-content: center;
    line-height: 1;
    padding: 0 0 2px;
    width: 38px;
}
.query-app-close:hover { background: var(--red-soft); border-color: #f3b8bb; color: var(--red-dark); }
.query-app-close:focus-visible { outline: 3px solid rgba(37, 99, 235, .2); outline-offset: 2px; }

.query-screen { margin: 0 auto; max-width: 1080px; padding: 20px; width: 100%; }
.query-toolbar, .query-new-header {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    margin-bottom: 16px;
}
h1 { font-family: var(--display); font-size: 22px; letter-spacing: .035em; margin: 0; }
.query-toolbar p, .query-new-header p { color: var(--muted); font-size: 12px; margin: 3px 0 0; }

.query-primary-button, .query-secondary-button, .query-resolve-button, .query-back-button {
    align-items: center;
    border-radius: 6px;
    display: inline-flex;
    font-family: var(--body);
    font-size: 12px;
    font-weight: 700;
    justify-content: center;
    min-height: 40px;
    padding: 9px 15px;
}
.query-primary-button { background: var(--red); border: 1px solid var(--red); color: #fff; }
.query-primary-button:hover { background: var(--red-dark); }
.query-primary-button:disabled { cursor: wait; opacity: .55; }
.query-secondary-button { background: #fff; border: 1px solid var(--line); color: var(--text); }
.query-resolve-button { background: #fff; border: 1px solid var(--line); color: var(--muted); margin-left: auto; }
.query-back-button { background: #fff; border: 1px solid var(--line); color: var(--text); flex: 0 0 auto; font-size: 20px; padding: 0; width: 40px; }

.query-category-tabs {
    display: flex;
    gap: 7px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.query-category-tabs::-webkit-scrollbar { display: none; }
.query-category-tabs button {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    display: inline-flex;
    flex: 0 0 auto;
    font-family: var(--display);
    font-size: 12px;
    font-weight: 700;
    gap: 6px;
    min-height: 36px;
    padding: 7px 12px;
}
.query-category-tabs button span { background: #eef1f5; border-radius: 999px; font-family: var(--body); font-size: 9px; padding: 2px 6px; }
.query-category-tabs button.is-active { background: var(--blue); border-color: var(--blue); color: #fff; }
.query-category-tabs button.is-active span { background: rgba(255,255,255,.2); }

.query-thread-list { display: grid; gap: 10px; }
.query-pagination {
    align-items: center;
    display: grid;
    gap: 10px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    margin-top: 14px;
}
.query-pagination button {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    font-family: var(--body);
    font-size: 10px;
    font-weight: 700;
    min-height: 36px;
    padding: 7px 12px;
}
.query-pagination button:hover:not(:disabled) { border-color: #93b4ff; color: var(--blue); }
.query-pagination button:disabled { color: #a8b0bc; cursor: default; opacity: .65; }
.query-pagination span { color: var(--muted); font-size: 10px; font-weight: 600; text-align: center; }
.query-thread-card {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-left: 4px solid var(--blue);
    border-radius: 10px;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 14px 16px;
    text-align: left;
    width: 100%;
}
.query-thread-card.is-pending { border-left-color: #d97706; }
.query-thread-card.is-replied, .query-thread-card.is-resolved { border-left-color: var(--green); }
.query-thread-card:hover { box-shadow: 0 8px 24px rgba(31,41,51,.07); }
.query-thread-main { min-width: 0; }
.query-thread-topline { align-items: center; display: flex; flex-wrap: wrap; gap: 7px; }
.query-id { font-family: var(--display); font-size: 15px; font-weight: 800; }
.query-chip {
    border-radius: 999px;
    display: inline-flex;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .035em;
    padding: 4px 8px;
    text-transform: uppercase;
}
.query-chip.category { background: var(--blue-soft); color: #1d4ed8; }
.query-chip.pending { background: var(--amber-soft); color: var(--amber); }
.query-chip.replied, .query-chip.resolved { background: var(--green-soft); color: var(--green); }
.query-chip.unread { background: var(--red-soft); color: var(--red-dark); }
.query-thread-preview { color: var(--muted); display: block; font-size: 12px; margin: 6px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.query-thread-meta { color: var(--muted); font-size: 10px; text-align: right; white-space: nowrap; }
.query-thread-chevron { color: var(--muted); display: block; font-size: 18px; margin-top: 8px; }

.query-empty, .query-auth-error {
    align-items: center;
    background: #fff;
    border: 1px dashed var(--line);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
    min-height: 220px;
    padding: 24px;
    text-align: center;
}
.query-empty span { color: var(--muted); font-size: 12px; }
.query-auth-error { color: var(--red-dark); margin: 32px auto; max-width: 520px; }

.query-screen--thread { display: flex; flex-direction: column; min-height: calc(100vh - 72px); }
.query-thread-header {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px 10px 0 0;
    display: grid;
    gap: 12px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 13px 16px;
}
.query-thread-header h1 { font-size: 18px; }
.query-thread-header p { color: var(--muted); font-size: 11px; margin: 3px 0 0; }
.query-message-timeline {
    background: #f8fafc;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 14px;
    min-height: 260px;
    overflow-y: auto;
    padding: 18px;
}
.query-message { display: flex; }
.query-message.coach { justify-content: flex-end; }
.query-message-bubble { background: #fff; border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; max-width: 72%; padding: 11px 13px; }
.query-message.coach .query-message-bubble { background: #eef4ff; border-color: #bfd2ff; border-radius: 14px 14px 4px 14px; }
.query-message-label { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.query-message-bubble p { font-size: 13px; line-height: 1.45; margin: 5px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.query-attachment { align-items: center; background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 7px; color: var(--blue); display: flex; font-size: 10px; gap: 6px; margin-top: 8px; max-width: 100%; overflow: hidden; padding: 6px 8px; text-decoration: none; }
.query-attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.query-composer, .query-new-form {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 0 0 10px 10px;
    padding: 14px 16px;
}
.query-read-only-note {
    background: var(--blue-soft);
    border: 1px solid #cbdcff;
    border-radius: 8px;
    color: #1e4f9d;
    font-size: 11px;
    margin: 0 16px 16px;
    padding: 10px 12px;
}
.query-composer-title { align-items: baseline; display: flex; gap: 10px; justify-content: space-between; margin-bottom: 8px; }
.query-composer-title strong, .query-field > span, legend { font-family: var(--display); font-size: 11px; letter-spacing: .045em; }
.query-composer-title span { color: var(--muted); font-size: 10px; }
.query-composer textarea, .query-new-form textarea {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
    min-height: 78px;
    padding: 11px 12px;
    resize: vertical;
    width: 100%;
}
.query-composer textarea:focus, .query-new-form textarea:focus { border-color: #93b4ff; outline: 2px solid rgba(37,99,235,.12); }
.query-composer-actions, .query-new-actions { align-items: center; display: flex; gap: 8px; margin-top: 10px; }
.query-file-button { cursor: pointer; }
.query-file-button input { display: none; }
.query-form-status { color: var(--muted); font-size: 9px; margin: 8px 0 0; }
.query-file-preview { align-items: center; background: var(--blue-soft); border-radius: 6px; color: #1d4ed8; display: flex; font-size: 10px; justify-content: space-between; margin-top: 8px; padding: 7px 9px; }
.query-file-preview button { background: transparent; border: 0; color: inherit; font-weight: 800; }

.query-new-header { justify-content: flex-start; }
.query-new-form { border-radius: 10px; }
.query-new-form fieldset { border: 0; margin: 0 0 16px; padding: 0; }
.query-new-form legend { margin-bottom: 8px; }
.query-new-categories { display: grid; gap: 9px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.query-new-categories label { cursor: pointer; min-width: 0; }
.query-new-categories input { opacity: 0; position: absolute; pointer-events: none; }
.query-new-categories span { background: #fff; border: 1px solid var(--line); border-radius: 8px; display: block; min-height: 78px; padding: 12px; }
.query-new-categories b { display: block; font-family: var(--display); font-size: 13px; }
.query-new-categories small { color: var(--muted); display: block; font-size: 9px; margin-top: 5px; }
.query-new-categories input:checked + span { background: var(--blue-soft); border-color: #7da3f8; color: #1d4ed8; }
.query-context { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; margin-top: 14px; padding: 11px 12px; }
.query-context strong { color: var(--muted); display: block; font-family: var(--display); font-size: 10px; letter-spacing: .045em; margin-bottom: 6px; }
.query-context p { font-size: 12px; line-height: 1.55; margin: 0; white-space: pre-wrap; }
.query-field { display: block; margin-top: 14px; }
.query-field > span { display: block; margin-bottom: 6px; }

@media (max-width: 680px) {
    .query-app-header { min-height: 62px; padding: 9px 12px; }
    .query-app-brand { height: 36px; width: 36px; }
    .query-app-heading strong { font-size: 17px; }
    .query-app-heading span { display: none; }
    .query-app-user strong { font-size: 10px; max-width: 120px; }
    .query-app-user span { font-size: 9px; }
    .query-app-close { height: 36px; width: 36px; }
    .query-screen { padding: 12px; }
    .query-toolbar { align-items: flex-start; }
    .query-toolbar h1 { font-size: 18px; }
    .query-toolbar p { display: none; }
    .query-toolbar .query-primary-button { min-height: 36px; padding: 7px 10px; }
    .query-category-tabs { margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; }
    .query-thread-card { gap: 7px; padding: 12px; }
    .query-thread-meta { font-size: 9px; }
    .query-screen--thread { min-height: calc(100vh - 62px); padding: 0; }
    .query-thread-header { border-left: 0; border-radius: 0; border-right: 0; padding: 10px 12px; position: sticky; top: 62px; z-index: 10; }
    .query-thread-header h1 { font-size: 16px; }
    .query-message-timeline { border-left: 0; border-right: 0; padding: 14px 10px; }
    .query-message-bubble { max-width: 86%; }
    .query-composer { border-bottom: 0; border-left: 0; border-radius: 0; border-right: 0; bottom: 0; padding: 10px; position: sticky; }
    .query-composer-title { align-items: flex-start; flex-direction: column; gap: 2px; }
    .query-composer textarea { min-height: 68px; }
    .query-composer-actions { flex-wrap: wrap; }
    .query-resolve-button { margin-left: 0; }
    .query-new-categories { grid-template-columns: 1fr; }
    .query-new-categories span { min-height: 62px; }
}

@media (max-width: 420px) {
    .query-app-user { display: none; }
    .query-thread-card { grid-template-columns: 1fr; }
    .query-thread-meta { display: flex; justify-content: space-between; text-align: left; }
    .query-thread-chevron { display: inline; margin: 0; }
    .query-composer-actions .query-primary-button, .query-new-actions .query-primary-button { flex: 1; }
}
