:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #172033;
    --muted: #667085;
    --line: #e4e7ec;
    --primary: #0b5fff;
    --primary-dark: #0747c8;
    --success: #067647;
    --warning: #b54708;
    --danger: #b42318;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: inherit; text-decoration: none; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 14px 22px;
    background: #111827;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
}
nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
nav a { opacity: .9; }
nav a:hover { opacity: 1; }
.inline { display: inline; margin: 0; }
.link-button { background: transparent; border: 0; color: #fff; cursor: pointer; font: inherit; padding: 0; }
.employee-chip { background: rgba(255,255,255,.12); padding: 7px 10px; border-radius: 999px; font-size: 14px; }
.container { max-width: 1160px; margin: 0 auto; padding: 28px 18px 60px; }
.hero {
    background: linear-gradient(135deg, #111827, #1d4ed8);
    color: #fff;
    border-radius: 22px;
    padding: 38px;
    margin-bottom: 24px;
    box-shadow: 0 16px 35px rgba(17,24,39,.18);
}
.hero h1 { margin: 5px 0 8px; font-size: clamp(34px, 6vw, 56px); }
.hero-kicker { text-transform: uppercase; letter-spacing: .12em; color: #bfdbfe; font-weight: 700; }
.lead { color: #e5e7eb; font-size: 18px; margin: 0; max-width: 720px; }
.page-head { margin: 6px 0 22px; }
.page-head h1 { margin: 0 0 6px; font-size: 32px; }
.page-head p { margin: 0; color: var(--muted); }
.row-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.form-card, .detail-card, .success-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 22px;
    box-shadow: 0 10px 24px rgba(16,24,40,.06);
    margin-bottom: 22px;
}
.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
label { display: block; font-weight: 700; margin: 14px 0 6px; }
input, select, textarea {
    width: 100%;
    padding: 12px 13px;
    border: 1px solid #cfd4dc;
    border-radius: 12px;
    font: inherit;
    background: #fff;
    color: var(--text);
}
textarea { resize: vertical; }
.required { color: var(--danger); }
.hint, .muted { color: var(--muted); font-size: 14px; }
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #cfd4dc;
    background: #fff;
    color: var(--text);
    border-radius: 12px;
    padding: 11px 15px;
    font-weight: 700;
    cursor: pointer;
    min-height: 42px;
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.full { width: 100%; margin-top: 14px; }
.btn.small { padding: 7px 10px; min-height: 34px; font-size: 13px; }
.messages { margin-bottom: 18px; }
.alert { padding: 13px 15px; border-radius: 12px; margin-bottom: 12px; border: 1px solid transparent; }
.alert-success { background: #ecfdf3; color: var(--success); border-color: #abefc6; }
.alert-info { background: #eff8ff; color: #175cd3; border-color: #b2ddff; }
.alert-warning { background: #fffaeb; color: var(--warning); border-color: #fedf89; }
.alert-danger { background: #fef3f2; color: var(--danger); border-color: #fecdca; }
.employee-status { border-left: 5px solid var(--primary); }
.employee-mini {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--line);
    padding: 11px 0;
}
.row:last-child { border-bottom: 0; }
.row span { color: var(--muted); }
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
}
.app-tile {
    display: flex;
    gap: 16px;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 20px;
    min-height: 130px;
    box-shadow: 0 10px 24px rgba(16,24,40,.06);
}
.app-tile:hover { transform: translateY(-1px); box-shadow: 0 16px 30px rgba(16,24,40,.1); }
.app-tile-icon { font-size: 36px; }
.app-tile-text { display: flex; flex-direction: column; gap: 7px; }
.app-tile-text small { color: var(--muted); line-height: 1.35; }
.form-grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f9fafb; color: #344054; font-size: 13px; }
.small { color: var(--muted); font-size: 13px; }
.badge { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-weight: 700; font-size: 12px; background: #eef2ff; color: #3538cd; }
.badge.ok { background: #ecfdf3; color: var(--success); }
.badge.danger { background: #fef3f2; color: var(--danger); }
.badge.new { background: #eff8ff; color: #175cd3; }
.badge.read { background: #f2f4f7; color: #344054; }
.badge.in_progress { background: #fffaeb; color: var(--warning); }
.badge.closed { background: #ecfdf3; color: var(--success); }
.empty-row { text-align: center; color: var(--muted); padding: 28px; }
.prebox { white-space: pre-wrap; background: #0f172a; color: #e5e7eb; padding: 16px; border-radius: 12px; overflow-x: auto; }
.document-list { display: flex; flex-direction: column; gap: 10px; }
.document-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.success-card { text-align: center; max-width: 720px; margin-left: auto; margin-right: auto; }
.success-icon { width: 70px; height: 70px; margin: 0 auto 12px; border-radius: 50%; background: #ecfdf3; color: var(--success); display: flex; align-items: center; justify-content: center; font-size: 42px; font-weight: 700; }
.request-no { font-size: 30px; font-weight: 800; background: #f8fafc; border: 1px dashed #98a2b3; border-radius: 14px; padding: 14px; margin: 12px auto; display: inline-block; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.center-actions { justify-content: center; margin-top: 18px; }
.footer { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding: 18px 22px; color: var(--muted); font-size: 13px; }
@media (max-width: 720px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    nav { width: 100%; }
    .hero { padding: 26px; }
    .row, .employee-mini, .document-row { flex-direction: column; }
    .form-grid.two { grid-template-columns: 1fr; }
}

.auto-email-box {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 14px 0 8px;
    padding: 13px 14px;
    border: 1px solid #abefc6;
    border-radius: 12px;
    background: #ecfdf3;
    color: var(--success);
}
.auto-email-box span {
    font-size: 14px;
    overflow-wrap: anywhere;
}
.auto-email-box.warning {
    border-color: #fedf89;
    background: #fffaeb;
    color: var(--warning);
}
.btn:disabled { opacity: .65; cursor: wait; }
.logout-note { margin-top: 18px; text-align: left; }

/* HR recipient accounts and status audit */
.hr-account-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 16px 0;
}
.hr-account-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    background: #f8fafc;
}
.hr-account-card h4 { margin: 0 0 8px; }
.status-history { display: flex; flex-direction: column; gap: 10px; }
.status-history-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
}
.status-arrow { margin: 0 8px; color: var(--muted); }
@media (max-width: 720px) {
    .hr-account-grid { grid-template-columns: 1fr; }
    .status-history-row { align-items: flex-start; flex-direction: column; }
}

/* HR replies */
.reply-form { border-left: 5px solid var(--primary); }
.mail-route {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 12px;
}
.mail-route > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mail-route span { color: var(--muted); font-size: 13px; }
.mail-route strong { overflow-wrap: anywhere; }
.mail-route.compact { margin: 10px 0; padding: 10px; }
.reply-history { display: flex; flex-direction: column; gap: 14px; }
.reply-history-row {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 15px;
    background: #fff;
}
.reply-history-head {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
}
.reply-history-head > div { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.reply-message {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 10px 0 0;
    padding: 14px;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--text);
    font: inherit;
    line-height: 1.5;
}
@media (max-width: 720px) {
    .mail-route { grid-template-columns: 1fr; }
    .reply-history-head { flex-direction: column; }
}

/* Conversation and ticket workflow */
.count-badge {
    display: inline-flex;
    min-width: 24px;
    height: 24px;
    padding: 0 7px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}
.request-list { display: flex; flex-direction: column; gap: 12px; }
.request-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 17px 18px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 8px 20px rgba(16,24,40,.05);
}
.request-list-item:hover { border-color: #98a2b3; box-shadow: 0 12px 26px rgba(16,24,40,.08); }
.request-list-item.has-unread { border-left: 5px solid var(--primary); background: #f8fbff; }
.request-list-main { min-width: 0; }
.request-list-title { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
.request-list-title strong { overflow-wrap: anywhere; }
.request-list-side { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; flex: 0 0 auto; }
.conversation { display: flex; flex-direction: column; gap: 14px; margin: 22px 0; }
.chat-message {
    width: min(82%, 820px);
    padding: 15px 17px;
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 7px 18px rgba(16,24,40,.05);
}
.chat-message.from-employee { align-self: flex-end; background: #eff6ff; border-bottom-right-radius: 5px; }
.chat-message.from-hr { align-self: flex-start; background: #fff; border-bottom-left-radius: 5px; }
.chat-message.internal-note { align-self: stretch; width: 100%; background: #fffaeb; border-color: #fedf89; border-style: dashed; }
.chat-head { display: flex; justify-content: space-between; gap: 14px; align-items: baseline; margin-bottom: 9px; }
.chat-head span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.chat-subject { font-weight: 700; color: #344054; margin-bottom: 8px; }
.chat-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.chat-files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.file-chip {
    display: inline-flex;
    align-items: center;
    padding: 7px 10px;
    border: 1px solid #b2ddff;
    background: #eff8ff;
    color: #175cd3;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
}
.file-chip:hover { background: #dff1ff; }
.warning-text { color: var(--warning); margin-top: 10px; }
.success-text { color: var(--success); margin-top: 10px; }
.request-summary { margin-bottom: 10px; }
.unread-row { background: #f8fbff; }
.badge.waiting_hr { background: #fff4ed; color: #b93815; }
.badge.waiting_employee { background: #eef4ff; color: #3538cd; }
.internal-form { border-left: 5px solid #f79009; }

@media (max-width: 720px) {
    .request-list-item { align-items: flex-start; flex-direction: column; }
    .request-list-side { align-items: flex-start; }
    .chat-message { width: 94%; }
    .chat-message.internal-note { width: 100%; }
    .chat-head { flex-direction: column; gap: 4px; }
}

.closed-conversation {
    border-left: 5px solid #175cd3;
    margin-bottom: 22px;
}

/* v1.3.0: unread messages, filters, audit and archive */
.nav-count {
    display: inline-flex;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    margin-left: 5px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #f04438;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
}
.new-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 8px;
    background: #d92d20;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.last-activity { margin-top: 7px; color: var(--muted); font-size: 13px; }
.view-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 0 0 18px;
}
.view-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    font-weight: 700;
}
.view-tab span {
    min-width: 24px;
    text-align: center;
    padding: 2px 7px;
    border-radius: 999px;
    background: #f2f4f7;
    font-size: 12px;
}
.view-tab.active { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
.view-tab.active span { background: var(--primary); color: #fff; }
.filter-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 18px;
    box-shadow: 0 8px 20px rgba(16,24,40,.05);
}
.filter-grid {
    display: grid;
    grid-template-columns: minmax(240px, 2fr) repeat(4, minmax(140px, 1fr));
    gap: 12px;
    align-items: end;
}
.audit-filter-grid { grid-template-columns: minmax(260px, 2fr) minmax(210px, 1fr) repeat(2, minmax(145px, 1fr)); }
.filter-grid label { margin: 0; }
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #f9fafb;
}
.checkbox-label input { width: auto; margin: 0; }
.filter-actions { display: flex; gap: 10px; margin-top: 14px; }
.settings-panel summary { cursor: pointer; font-size: 18px; }
.settings-panel[open] summary { margin-bottom: 18px; }
.archive-setting { max-width: 360px; margin-top: 22px; }
.input-with-suffix { display: flex; align-items: center; gap: 10px; }
.input-with-suffix input { max-width: 170px; }
.input-with-suffix span { color: var(--muted); font-weight: 700; }
.badge.archived { background: #f2f4f7; color: #344054; }
.audit-link { color: var(--primary); font-weight: 700; }
.audit-table { min-width: 1080px; }
.audit-timeline { display: flex; flex-direction: column; }
.audit-timeline-row {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 13px 0;
    border-bottom: 1px solid var(--line);
}
.audit-timeline-row:last-child { border-bottom: 0; }
.audit-meta { min-width: 245px; text-align: right; }
.audit-section-head { margin-bottom: 8px; }
.audit-section-head h3 { margin: 0; }

@media (max-width: 980px) {
    .filter-grid, .audit-filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
    .filter-grid, .audit-filter-grid { grid-template-columns: 1fr; }
    .filter-actions { flex-direction: column; }
    .audit-timeline-row { flex-direction: column; }
    .audit-meta { min-width: 0; text-align: left; }
}
