/* ==================================================================
   Design tokens
   Palette: warm graphite ink on a cool paper background, with a
   single deep-teal accent used sparingly (status/actions only) -
   deliberately steering away from the cream+terracotta or
   near-black+neon-accent looks that read as "AI generated default".
   Type: system UI stack for body (fast, native, no web-font flash),
   tabular figures for numeric columns so tables line up.
================================================================== */
:root {
    --paper:        #F5F6F4;
    --surface:      #FFFFFF;
    --ink:          #1C2320;
    --ink-soft:     #5B655F;
    --line:         #DFE3DE;
    --accent:       #0E6E63;
    --accent-soft:  #E4F1EE;
    --accent-ink:   #06332C;
    --warn:         #A45A2A;
    --danger:       #B3402F;
    --danger-soft:  #FBEAE7;
    --radius:       8px;
    --shadow:       0 1px 2px rgba(20, 30, 25, 0.06), 0 1px 1px rgba(20,30,25,0.04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: -apple-system, "Segoe UI", "Inter", system-ui, sans-serif;
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--ink-soft); font-size: 0.85em; }
.warn { color: var(--warn); }

/* ---------- Top bar / tabs ---------- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 40px;
    height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark {
    width: 28px; height: 28px;
    border-radius: 6px;
    background: var(--accent-ink);
    color: #EAF3F1;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
}
.tabs { display: flex; gap: 4px; height: 100%; }
.tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--ink-soft);
    font: inherit;
    font-weight: 500;
    padding: 0 4px;
    height: 100%;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.tab + .tab { margin-left: 28px; }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.topbar-user { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.topbar-user .user-name { white-space: nowrap; }
.user-avatar { width: 26px; height: 26px; border-radius: 50%; }

/* ---------- Login page ---------- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--paper);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
    width: 320px;
    text-align: center;
}
.login-card .brand { justify-content: center; margin-bottom: 14px; }
.login-card p { margin: 0 0 18px; }
.login-card .alert { text-align: left; margin-bottom: 16px; }
.login-google-btn { width: 100%; justify-content: center; }

/* ---------- Layout ---------- */
.app-main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; transition: max-width 0.15s ease; }
.app-main.is-wide { max-width: 1680px; }
.panel { display: none; }
.panel.is-active { display: block; }

.grid-two { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid-two { grid-template-columns: 1fr; } }

.stack { display: flex; flex-direction: column; gap: 20px; }
.stack-tight { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow);
}
.card-head { margin-bottom: 16px; }
.card-head h2 { margin: 0 0 4px; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.card-head p { margin: 0; }

/* ---------- Forms ---------- */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: end; }
.field-row-3 .field-op select { width: auto; min-width: 78px; padding-right: 22px; }
@media (max-width: 700px) { .field-row-3 { grid-template-columns: 1fr; } .field-row-3 .field-op { justify-self: start; } }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.full-width { width: 100%; }

select, input[type="text"], input[type="date"] {
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
}
select:disabled { background: #F1F2F0; color: var(--ink-soft); }
select:focus, input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.checkbox-line { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; cursor: pointer; }
.checkbox-line input { margin-top: 3px; }

.tag-input {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    background: var(--surface);
}
.tag-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-input input { border: none; flex: 1; min-width: 120px; padding: 4px 2px; }
.tag-input input:focus { box-shadow: none; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
    background: var(--accent-soft);
    color: var(--accent-ink);
    border-radius: 999px;
    padding: 3px 8px 3px 10px;
    font-size: 12.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.tag.is-not-contains { background: var(--danger-soft); color: var(--danger); }
.tag-text { cursor: pointer; }
.tag-text:hover { text-decoration: underline; }
.tag button {
    background: none; border: none; cursor: pointer;
    color: inherit; font-size: 13px; line-height: 1;
    opacity: 0.6;
}
.tag button:hover { opacity: 1; }

.btn {
    font: inherit;
    font-weight: 600;
    border-radius: 6px;
    padding: 9px 16px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); font-weight: 500; font-size: 13px; padding: 7px 12px; }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.file-btn { display: inline-flex; align-items: center; }

.alert {
    background: var(--danger-soft);
    border-left: 3px solid var(--danger);
    color: #6E2A1D;
    padding: 10px 12px;
    border-radius: 4px;
    font-size: 13px;
}

/* ---------- Tracker tabs (Issue / Feature Request) ---------- */
.tracker-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.tracker-toolbar select { min-width: 200px; }
.summary-banner {
    background: var(--accent-soft);
    color: var(--accent-ink);
    border-radius: var(--radius);
    padding: 14px 18px;
    font-size: 13.5px;
    margin-bottom: 18px;
}
.chart-card { margin-bottom: 20px; height: 260px; }
.chart-card canvas { max-height: 220px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
}
table.data-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    font-variant-numeric: tabular-nums;
}
table.data-table tr:hover td { background: var(--paper); }
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: var(--accent-soft);
    color: var(--accent-ink);
}
.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--ink-soft);
}

/* ---------- Sortable table headers ---------- */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent-ink); }
.sort-arrow { display: inline-block; margin-left: 4px; font-size: 10px; color: var(--accent); }

/* ---------- Clickable rows (drill-down) ---------- */
tr.row-clickable { cursor: pointer; }

/* ---------- Trending insights ---------- */
.insight-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    font-size: 13.5px;
}
.insight-item:last-child { border-bottom: none; }
.insight-key {
    flex-shrink: 0;
    font-weight: 700;
    color: var(--accent-ink);
    background: var(--accent-soft);
    border-radius: 6px;
    padding: 2px 8px;
    height: fit-content;
    font-size: 12px;
}
.insight-text { color: var(--ink); line-height: 1.5; }

/* ---------- Sub-tabs (within a top-level tab, e.g. Zendesk Exporter) ---------- */
.subtabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 20px;
}
.subtab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--ink-soft);
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    padding: 10px 4px;
    cursor: pointer;
}
.subtab + .subtab { margin-left: 20px; }
.subtab:hover { color: var(--ink); }
.subtab.is-active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.subpanel { display: none; }
.subpanel.is-active { display: block; }

/* ---------- Modal (AI Analysis: archived questions) ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 30, 25, 0.45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 20px;
    z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 24px;
    width: 100%;
    max-width: 880px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: hidden;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.modal-head h2 { margin: 0 0 4px; font-size: 16px; font-weight: 650; }
.modal-head p { margin: 0; }
.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    color: var(--ink-soft);
    padding: 2px 6px;
}
.modal-close:hover { color: var(--ink); }
.modal-scroll { overflow: auto; }

.keyword-help { margin: 8px 0 10px; line-height: 1.5; }
.keyword-help code {
    background: var(--accent-soft);
    color: var(--accent-ink);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.92em;
}

/* ---------- ZD Report Editor table ---------- */
#re_table td { vertical-align: middle; }
.btn-link-small {
    background: none; border: none; cursor: pointer;
    color: var(--accent-ink); font-size: 12px; font-weight: 600; padding: 2px 0;
    text-decoration: underline; text-underline-offset: 2px;
}
.btn-link-small:hover { color: var(--accent); }

.re-jira-cell { position: relative; display: flex; align-items: center; gap: 6px; }
.re-service-type-select { font-size: 12.5px; padding: 4px 6px; max-width: 150px; }
.re-service-type-select:disabled { background: var(--paper); color: var(--ink-soft); cursor: not-allowed; }
.re-jira-input {
    font-size: 12.5px;
    padding: 4px 8px;
    width: 130px;
}
.re-jira-open {
    color: var(--accent-ink);
    text-decoration: none;
    font-size: 13px;
    flex-shrink: 0;
}
.re-jira-open:hover { color: var(--accent); }

/* Excel-style fill handle at the bottom-right corner of a filled cell */
.re-fill-handle {
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 9px;
    height: 9px;
    background: var(--accent);
    border: 1px solid #fff;
    border-radius: 1px;
    cursor: crosshair;
}
tr.re-fill-target td { background: var(--accent-soft); }

/* On-demand conversation history row */
.re-history-cell { background: var(--paper); padding: 14px 18px; font-size: 13px; }
.re-history-comment { padding: 8px 0; border-bottom: 1px solid var(--line); }
.re-history-comment:last-child { border-bottom: none; }
.re-history-meta { color: var(--ink-soft); font-size: 11.5px; margin-bottom: 3px; }

/* ---------- Toasts ---------- */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
}
.toast {
    background: var(--ink);
    color: #fff;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: toast-in 0.15s ease;
}
.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: var(--accent-ink); }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Dashboard "Open in Jira" link (Issue/Feature Request Tracker) ---------- */
.jira-open-link {
    color: var(--accent-ink);
    text-decoration: none;
    font-size: 13px;
}
.jira-open-link:hover { text-decoration: underline; }

/* ---------- AI Analysis: trend arrows + popularity-over-time sparkline ---------- */
.trend-icon {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    margin-left: 4px;
    padding: 1px 5px;
    border-radius: 999px;
    vertical-align: middle;
}
.trend-up { color: #fff; background: var(--accent); }
.trend-down { color: #fff; background: var(--danger); }
.trend-new { color: var(--accent-ink); background: var(--accent-soft); }
.sparkline { display: block; }

/* ---------- AI Analysis: Source of Truth summary write-up ---------- */
.ai-summary-card { margin: 18px 0; }
.ai-summary h3 { margin: 0 0 6px; font-size: 15px; font-weight: 650; }
.ai-summary p { margin: 0 0 10px; }
.ai-summary ul { margin: 0; padding-left: 20px; }
.ai-summary li { margin-bottom: 4px; }
.ai-summary-meta { color: var(--ink-soft); font-size: 12px; }

/* ---------- AI Analysis: Customer Expected Roadmap "slide" ---------- */
.roadmap-slide {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
}
.roadmap-title {
    margin: 0 0 6px;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-align: center;
    color: var(--accent-ink);
}
.roadmap-subtitle {
    margin: 0 0 28px;
    text-align: center;
    color: var(--ink-soft);
}
.roadmap-swimlanes {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}
@media (max-width: 1000px) { .roadmap-swimlanes { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .roadmap-swimlanes { grid-template-columns: 1fr; } }
.roadmap-lane {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.roadmap-lane-head {
    font-weight: 700;
    font-size: 13px;
    color: var(--accent-ink);
    text-align: center;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--accent);
}
.roadmap-lane-cards { display: flex; flex-direction: column; gap: 10px; }
.roadmap-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    box-shadow: var(--shadow);
}
.roadmap-card-title { font-weight: 650; font-size: 13.5px; margin-bottom: 4px; }
.roadmap-card-desc { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 8px; line-height: 1.4; }
.roadmap-card-foot { display: flex; flex-wrap: wrap; gap: 6px; }
