* { box-sizing: border-box; }

:root {
    --ribbon-bg: #f2f2f2;
    --ribbon-border: #d4d4d4;
    --accent-blue: #2d6ca2;
    --sidebar-bg: #fafafa;
    --row-hover: #eaf3fb;
    --row-selected: #cfe4f7;
    --overdue-bg: #fbdcdc;
    --overdue-text: #8a1f1f;
    --group-bg: #e8e8e8;
    --text: #1d1d1d;
    --text-dim: #6b6b6b;
    --border: #d9d9d9;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 13px;
    color: var(--text);
    background: #ffffff;
}

/* Ribbon / toolbar */
.ribbon {
    background: var(--ribbon-bg);
    border-bottom: 1px solid var(--ribbon-border);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 22px;
}

.ribbon .title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-right: 12px;
}

.ribbon-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: none;
    background: transparent;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    font-size: 11px;
    color: var(--text);
    text-decoration: none;
}

.ribbon-btn:hover {
    background: #e2e2e2;
}

.ribbon-btn .icon {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    background: var(--accent-blue);
    color: white;
}

/* Smart search (ribbon) */
.smart-search {
    position: relative;
    flex: 1;
    max-width: 420px;
}

.smart-search input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    background: #ffffff;
    color: var(--text);
}

.smart-search input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.smart-search-results {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    max-height: 320px;
    overflow-y: auto;
    z-index: 50;
}

.smart-search-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    text-decoration: none;
    color: var(--text);
    font-size: 12px;
    border-bottom: 1px solid var(--border);
}

.smart-search-item:last-child {
    border-bottom: none;
}

.smart-search-item:hover,
.smart-search-item.active {
    background: var(--row-hover);
}

.smart-search-item .ssi-num {
    color: var(--text-dim);
    flex-shrink: 0;
}

.smart-search-item .ssi-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.smart-search-item .ssi-meta {
    color: var(--text-dim);
    flex-shrink: 0;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.smart-search-empty {
    padding: 10px;
    font-size: 12px;
    color: var(--text-dim);
}

/* Layout */
.layout {
    display: flex;
    height: calc(100vh - 54px);
}

.sidebar {
    width: 220px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 10px 0;
}

.sidebar h3 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-dim);
    padding: 0 12px;
    margin: 4px 0 8px;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
}

.sidebar a:hover,
.sidebar a.active {
    background: var(--row-selected);
}

.sidebar a .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-blue);
}

.main {
    flex: 1;
    overflow-y: auto;
}

.main h2 {
    padding: 12px 16px 6px;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

/* Filters popover (ribbon) */
.filter-popover-wrap {
    position: relative;
}

#filter-toggle-btn.filter-active {
    background: var(--accent-blue);
    color: #fff;
}

#filter-toggle-btn.filter-active .icon {
    filter: brightness(0) invert(1);
}

.filter-popover {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 50;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    padding: 12px;
    flex-direction: column;
    gap: 10px;
    width: 280px;
}

.filter-popover.open {
    display: flex;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.filter-field label {
    font-size: 11px;
    color: var(--text-dim);
}

.filter-field select,
.filter-field input {
    padding: 5px 6px;
    font-size: 13px;
    width: 100%;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
}

.filter-popover-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}

.filter-popover-actions button[type="submit"] {
    padding: 6px 16px;
}

.filter-reset {
    font-size: 12px;
    color: var(--text-dim);
}

/* Table */
table.ticket-table {
    width: 100%;
    border-collapse: collapse;
}

table.ticket-table thead th {
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-dim);
    background: #f7f7f7;
    border-bottom: 1px solid var(--border);
    padding: 6px 10px;
    position: sticky;
    top: 0;
}

table.ticket-table tr.group-row td {
    background: var(--group-bg);
    font-weight: 600;
    padding: 5px 10px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}

table.ticket-table tbody tr.ticket-row {
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

table.ticket-table tbody tr.ticket-row:hover {
    background: var(--row-hover);
}

table.ticket-table tbody tr.ticket-row.overdue {
    background: var(--overdue-bg);
    color: var(--overdue-text);
}

table.ticket-table tbody tr.ticket-row.closed {
    color: var(--text-dim);
    text-decoration: line-through;
    text-decoration-color: #c9c9c9;
}

table.ticket-table td {
    padding: 6px 10px;
    vertical-align: top;
    white-space: nowrap;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
}

td.desc-cell {
    white-space: normal;
}

.badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 600;
}

.badge.prio-high { background: #fbdcdc; color: #8a1f1f; }
.badge.prio-medium { background: #fdf0cf; color: #8a650f; }
.badge.prio-low { background: #dcedda; color: #1f6b2a; }

.badge.status-open { background: #dbe9f8; color: #2d6ca2; }
.badge.status-in_progress { background: #fdf0cf; color: #8a650f; }
.badge.status-waiting_for_response { background: #f3d9f9; color: #7a2f8a; }
.badge.status-closed { background: #e4e4e4; color: #6b6b6b; }

.empty-state {
    padding: 40px;
    text-align: center;
    color: var(--text-dim);
}

/* Detail page */
.detail-wrap {
    padding: 18px 24px;
    max-width: 900px;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 14px;
}

.detail-header h1 {
    font-size: 18px;
    margin: 0 0 4px;
}

.detail-meta {
    color: var(--text-dim);
    font-size: 12px;
}

.detail-box {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 14px;
    margin-bottom: 16px;
    background: #fcfcfc;
}

.detail-box h3 {
    margin: 0 0 8px;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.transcript .msg {
    padding: 6px 0;
    border-bottom: 1px solid #f0f0f0;
}

.transcript .msg .author {
    font-weight: 600;
    margin-right: 6px;
}

.transcript .msg .time {
    color: var(--text-dim);
    font-size: 11px;
}

.transcript .msg .msg-content {
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-content .md-quote {
    display: block;
    padding-left: 8px;
    border-left: 3px solid var(--border);
    color: var(--text-dim);
}

.msg-content code {
    background: rgba(0, 0, 0, 0.08);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
    font-size: 0.92em;
}

.status-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.status-form select,
.status-form input[type="text"],
.status-form button {
    padding: 4px 8px;
    font-size: 13px;
}

/* Settings page */
.settings-layout {
    display: flex;
    align-items: flex-start;
    gap: 24px;
    padding: 18px 24px;
    max-width: 1100px;
}

.settings-nav {
    position: sticky;
    top: 18px;
    flex-shrink: 0;
    width: 180px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.settings-nav-title {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-dim);
    font-weight: 600;
    margin-bottom: 6px;
}

.settings-nav a {
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    padding: 6px 8px;
    border-radius: 4px;
}

.settings-nav a:hover {
    background: var(--row-hover);
}

.settings-content {
    flex: 1;
    min-width: 0;
    max-width: 820px;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field-wide {
    grid-column: 1 / -1;
}

.field label {
    font-weight: 600;
    font-size: 13px;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
    width: 100%;
    padding: 6px 8px;
    font-family: inherit;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #ffffff;
    color: var(--text);
}

.field textarea {
    resize: vertical;
}

.field-help {
    color: var(--text-dim);
    font-size: 11px;
    margin: 0;
}

.toggle-field {
    justify-content: center;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 10px;
}

.checkbox-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 2px;
    font-size: 13px;
    cursor: pointer;
    border-radius: 3px;
}

.checkbox-list-item:hover {
    background: var(--bg-hover, rgba(45, 108, 162, 0.08));
}

.checkbox-list-item input[type="checkbox"] {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

@media (max-width: 760px) {
    .settings-layout {
        flex-direction: column;
    }
    .settings-nav {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        width: auto;
    }
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

a.back-link {
    color: var(--accent-blue);
    text-decoration: none;
    font-size: 12px;
}

a.discord-link {
    color: var(--accent-blue);
    text-decoration: none;
}

/* AI agent chat */
.ai-chat-log {
    max-height: 420px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 2px;
}

.ai-chat-msg {
    max-width: 85%;
    border-radius: 6px;
    padding: 8px 10px;
}

.ai-chat-user {
    align-self: flex-end;
    background: var(--row-selected);
}

.ai-chat-assistant {
    align-self: flex-start;
    background: var(--group-bg);
}

.ai-chat-author {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 2px;
}

.ai-chat-content {
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-pending-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.ai-pending-item:last-child {
    border-bottom: none;
}

.ai-pending-item button {
    padding: 4px 8px;
    font-size: 12px;
}
