/* ==========================================================================
   Letter Tracking System - stylesheet
   Deliberately framework free so the whole app deploys as plain files.
   ========================================================================== */

:root {
    --navy:      #1f4e79;
    --navy-dark: #16395a;
    --navy-soft: #e8f0f8;
    --accent:    #c8102e;
    --green:     #1e7b45;
    --amber:     #b56a00;
    --red:       #b3261e;
    --grey-1:    #f5f7fa;
    --grey-2:    #e3e8ee;
    --grey-3:    #b9c3cf;
    --text:      #1c2733;
    --muted:     #64748b;
    --white:     #ffffff;
    --radius:    8px;
    --shadow:    0 1px 3px rgba(16, 39, 64, .12), 0 1px 2px rgba(16, 39, 64, .08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--grey-1);
    color: var(--text);
    font-family: 'Nirmala UI', 'Mangal', 'Segoe UI', Roboto, Arial, sans-serif;
    font-size: 14.5px;
    line-height: 1.5;
}

a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ topbar */
.topbar {
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-dark) 100%);
    color: #fff;
    border-bottom: 3px solid var(--accent);
}
.topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    font-size: 26px;
    background: rgba(255,255,255,.14);
    border-radius: 50%;
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; }
.brand-title { font-size: 19px; font-weight: 700; letter-spacing: .2px; }
.brand-sub   { font-size: 12px; opacity: .8; }

.userbox { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.user-name   { font-weight: 600; }
.user-office { font-size: 12px; opacity: .85; background: rgba(255,255,255,.12);
               padding: 2px 9px; border-radius: 20px; }
.btn-logout {
    background: rgba(255,255,255,.14);
    color: #fff !important;
    padding: 5px 13px;
    border-radius: 20px;
    font-size: 12.5px;
    text-decoration: none !important;
    border: 1px solid rgba(255,255,255,.25);
}
.btn-logout:hover { background: var(--accent); border-color: var(--accent); }

/* --------------------------------------------------------------------- nav */
.mainnav { background: var(--white); border-bottom: 1px solid var(--grey-2); box-shadow: var(--shadow); }
.mainnav-inner {
    max-width: 1400px; margin: 0 auto; padding: 0 20px;
    display: flex; gap: 2px; flex-wrap: wrap;
}
.navlink {
    display: flex; align-items: center; gap: 7px;
    padding: 12px 16px;
    font-size: 14px; font-weight: 600;
    color: var(--muted) !important;
    border-bottom: 3px solid transparent;
    text-decoration: none !important;
}
.navlink .ni { font-size: 15px; opacity: .85; }
.navlink:hover { color: var(--navy) !important; background: var(--navy-soft); }
.navlink.active { color: var(--navy) !important; border-bottom-color: var(--accent); background: var(--navy-soft); }

/* -------------------------------------------------------------- containers */
.wrap { max-width: 1400px; margin: 0 auto; padding: 20px; }

.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.page-title { font-size: 21px; font-weight: 700; margin: 0; color: var(--navy); }
.page-sub   { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* --------------------------------------------------------- quick links */
.quick-links { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.quick-link {
    display: flex; align-items: center; gap: 9px;
    background: var(--white); border: 1px solid var(--grey-2); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 9px 13px; width: 190px;
    text-decoration: none !important;
}
.quick-link:hover { border-color: var(--navy); background: var(--navy-soft); }
.quick-link .ql-icon {
    font-size: 16px; color: var(--navy); flex: 0 0 auto;
    width: 30px; height: 30px; border-radius: 50%; background: var(--navy-soft);
    display: flex; align-items: center; justify-content: center;
}
.quick-link .ql-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.quick-link .ql-title { font-size: 13px; font-weight: 700; color: var(--navy); }
.quick-link .ql-desc { font-size: 11px; color: var(--muted); line-height: 1.3; }

.card {
    background: var(--white);
    border: 1px solid var(--grey-2);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 18px;
}
.card-title {
    font-size: 15px; font-weight: 700; color: var(--navy);
    margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--grey-2);
    display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.card-title .hint { font-size: 12px; font-weight: 400; color: var(--muted); }

/* -------------------------------------------------------------- stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile {
    background: var(--white); border: 1px solid var(--grey-2); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 14px 16px; position: relative; overflow: hidden;
    border-left: 4px solid var(--navy);
}
.tile.t-pending  { border-left-color: var(--amber); }
.tile.t-overdue  { border-left-color: var(--red); }
.tile.t-replied  { border-left-color: var(--green); }
.tile.t-closed   { border-left-color: var(--navy); }
.tile.t-info     { border-left-color: var(--grey-3); }
.tile-label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.tile-value { font-size: 30px; font-weight: 700; line-height: 1.12; margin-top: 4px; }
.tile-foot  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile-value.c-pending { color: var(--amber); }
.tile-value.c-overdue { color: var(--red); }
.tile-value.c-replied { color: var(--green); }
.tile-value.c-closed  { color: var(--navy); }

/* ------------------------------------------------------------------ badges */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 20px;
    font-size: 11.5px; font-weight: 700; white-space: nowrap; border: 1px solid transparent;
}
.st-pending     { background: #fff4e0; color: #8a5200; border-color: #f2d9a8; }
.st-replied     { background: #e6f6ec; color: #14653a; border-color: #b9e4c9; }
.st-closed      { background: #e8eef5; color: #1f4e79; border-color: #c3d4e6; }
.st-none        { background: var(--grey-1); color: var(--muted); }

.pri-normal     { background: #eef2f7; color: #33475b; border-color: #d3dce6; }
.pri-urgent     { background: #fdeaea; color: #a01818; border-color: #f4c2c2; }
.pri-long       { background: #f1ecfb; color: #5a3fa8; border-color: #d9cdf5; }

.due-ok         { background: #eef6ff; color: #22557f; border-color: #cfe2f5; }
.due-soon       { background: #fff4e0; color: #8a5200; border-color: #f2d9a8; }
.due-overdue    { background: #fdeaea; color: #a01818; border-color: #f4c2c2; }
.due-closed     { background: #eef1f4; color: #5b6b7c; border-color: #dde3e9; }

.badge-info     { background: #eef2f7; color: #33475b; border-color: #d3dce6; }

/* ------------------------------------------------------------------- grids */
.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.grid thead th {
    background: var(--navy); color: #fff; text-align: left;
    padding: 9px 10px; font-weight: 600; font-size: 13px; white-space: nowrap;
    position: sticky; top: 0; z-index: 2;
}
.grid tbody td { padding: 8px 10px; border-bottom: 1px solid var(--grey-2); vertical-align: top; }
.grid tbody tr:nth-child(even) { background: #fbfcfe; }
.grid tbody tr:hover { background: var(--navy-soft); }
.grid-wrap { overflow-x: auto; border: 1px solid var(--grey-2); border-radius: var(--radius); background: var(--white); }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .nowrap { white-space: nowrap; }
.grid-empty { padding: 26px; text-align: center; color: var(--muted); }

.row-overdue td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.row-duesoon td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.subject-cell { max-width: 460px; }
.subject-cell .s1 { font-weight: 600; }
.subject-cell .s2 { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------- forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.span-2 { grid-column: span 2; }
.field.span-all { grid-column: 1 / -1; }
.field > label { font-size: 12.5px; font-weight: 600; color: #3b4a5a; }
.field .req { color: var(--accent); }

input[type=text], input[type=password], input[type=date], input[type=number],
input[type=email], select, textarea {
    width: 100%; padding: 8px 10px; font-size: 14px;
    border: 1px solid var(--grey-3); border-radius: 6px;
    background: var(--white); color: var(--text);
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(31,78,121,.14);
}
textarea { min-height: 88px; resize: vertical; }
.hint-text { font-size: 11.5px; color: var(--muted); }

/* ----------------------------------------------------------------- buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 15px; border-radius: 6px; border: 1px solid var(--navy);
    background: var(--navy); color: #fff !important; font-size: 13.5px; font-weight: 600;
    cursor: pointer; text-decoration: none !important; font-family: inherit; line-height: 1.3;
}
.btn:hover { background: var(--navy-dark); border-color: var(--navy-dark); }
.btn-sec { background: var(--white); color: var(--navy) !important; border-color: var(--grey-3); }
.btn-sec:hover { background: var(--navy-soft); border-color: var(--navy); }
.btn-danger { background: var(--accent); border-color: var(--accent); }
.btn-danger:hover { background: #a50d25; border-color: #a50d25; }
.btn-green { background: var(--green); border-color: var(--green); }
.btn-green:hover { background: #176034; border-color: #176034; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }

/* --------------------------------------------------------------- messages */
.flash { padding: 11px 15px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 600; font-size: 13.5px; }
.flash-ok  { background: #e6f6ec; color: #14653a; border: 1px solid #b9e4c9; }
.flash-err { background: #fdeaea; color: #a01818; border: 1px solid #f4c2c2; }
.error-text { color: var(--red); font-weight: 600; }
.empty-note { color: var(--muted); padding: 16px 0; text-align: center; }

/* ---------------------------------------------------------------- filters */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.filters .actions { display: flex; gap: 8px; }

/* ---------------------------------------------------------------- timeline */
.timeline { position: relative; margin: 0; padding: 4px 0 4px 0; list-style: none; }
.timeline::before {
    content: ''; position: absolute; left: 17px; top: 8px; bottom: 8px;
    width: 2px; background: var(--grey-2);
}
.tl-item { position: relative; padding: 0 0 16px 48px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot {
    position: absolute; left: 6px; top: 0;
    width: 24px; height: 24px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; color: #fff; background: var(--grey-3);
    border: 2px solid var(--white); box-shadow: 0 0 0 1px var(--grey-2);
}
.tl-created  .tl-dot { background: var(--navy); }
.tl-sent     .tl-dot { background: #2f6fa8; }
.tl-reply    .tl-dot { background: var(--green); }
.tl-closed   .tl-dot { background: #14653a; }
.tl-reopened .tl-dot { background: var(--amber); }
.tl-edited   .tl-dot { background: #6b7f95; }
.tl-attach   .tl-dot { background: #5a3fa8; }
.tl-deleted  .tl-dot { background: var(--red); }
.tl-body { background: var(--grey-1); border: 1px solid var(--grey-2); border-radius: 6px; padding: 9px 12px; }
.tl-head { font-weight: 700; font-size: 13.5px; }
.tl-meta { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.tl-text { font-size: 13px; margin-top: 5px; white-space: pre-wrap; }

/* -------------------------------------------------------------- key/value */
.kv { display: grid; grid-template-columns: 190px 1fr; gap: 0; font-size: 13.5px; }
.kv dt { padding: 7px 10px; background: var(--grey-1); font-weight: 600; color: #3b4a5a; border-bottom: 1px solid var(--grey-2); }
.kv dd { padding: 7px 10px; margin: 0; border-bottom: 1px solid var(--grey-2); word-break: break-word; }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: none; }

/* ------------------------------------------------------------------- bars */
.bar-row { display: grid; grid-template-columns: 130px 1fr 52px; gap: 10px; align-items: center; margin-bottom: 7px; font-size: 13px; }
.bar-track { background: var(--grey-2); border-radius: 10px; height: 16px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--navy); border-radius: 10px; }
.bar-fill.b-urgent  { background: var(--red); }
.bar-fill.b-pending { background: var(--amber); }
.bar-fill.b-replied { background: var(--green); }
.bar-num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ misc */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }
.pager { display: flex; gap: 6px; align-items: center; margin-top: 12px; flex-wrap: wrap; font-size: 13px; }
.pager a, .pager span { padding: 5px 10px; border: 1px solid var(--grey-2); border-radius: 5px; background: var(--white); }
.pager .cur { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 700; }
.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.spacer { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, 'Cascadia Mono', monospace; }
.tag-informative { background: #eef2f7; color: #46586b; border: 1px solid #d3dce6; padding: 1px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.reopen-flag { color: var(--amber); font-weight: 700; font-size: 11.5px; }

/* ------------------------------------------------------------- login page */
.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(140deg, #16395a 0%, #1f4e79 45%, #2a6ba3 100%);
    padding: 24px;
}
.login-card {
    width: 100%; max-width: 420px; background: var(--white);
    border-radius: 12px; box-shadow: 0 18px 50px rgba(0,0,0,.35);
    overflow: hidden;
}
.login-head { background: var(--navy); color: #fff; padding: 22px 24px; text-align: center; border-bottom: 3px solid var(--accent); }
.login-head .lh-mark { font-size: 34px; }
.login-head h1 { font-size: 18px; margin: 6px 0 2px; }
.login-head p { font-size: 12px; opacity: .85; margin: 0; }
.login-body-inner { padding: 22px 24px 26px; }
.login-body-inner .field { margin-bottom: 14px; }
.login-foot { text-align: center; font-size: 11.5px; color: var(--muted); padding: 0 24px 20px; }
.login-error { background: #fdeaea; color: #a01818; border: 1px solid #f4c2c2; padding: 10px 13px; border-radius: 6px; margin-bottom: 15px; font-size: 13px; font-weight: 600; }
.login-hint { background: var(--navy-soft); border: 1px solid #cfe0f0; color: #23486b; padding: 9px 12px; border-radius: 6px; font-size: 12px; margin-top: 14px; }

/* ---------------------------------------------------------------- footer */
.footer { border-top: 1px solid var(--grey-2); background: var(--white); margin-top: 26px; }
.footer-inner {
    max-width: 1400px; margin: 0 auto; padding: 13px 20px;
    display: flex; gap: 16px; justify-content: space-between; flex-wrap: wrap;
    font-size: 12px; color: var(--muted);
}

/* ----------------------------------------------------------------- print */
@media print {
    .topbar, .mainnav, .footer, .no-print, .btn, .pager { display: none !important; }
    body { background: #fff; font-size: 11.5pt; }
    .wrap { padding: 0; max-width: none; }
    .card { box-shadow: none; border: none; padding: 0; margin-bottom: 12px; }
    .grid thead th { background: #e8e8e8 !important; color: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .grid tbody td { border-bottom: 1px solid #ccc; }
    a { color: #000; text-decoration: none; }
    .grid { font-size: 10pt; }
    .print-only { display: block !important; }
}
.print-only { display: none; }

/* --------------------------------------------------- multi-recipient entry */
.recipient-grid td { padding: 6px 7px; }
.recipient-grid input[type=text],
.recipient-grid select,
.recipient-grid textarea { padding: 6px 8px; font-size: 13px; }
.recipient-grid select { min-width: 100%; }
.recipient-grid .other-dept { border-color: var(--amber); }
.rowno {
    text-align: center; color: var(--muted); font-weight: 700;
    font-variant-numeric: tabular-nums; background: var(--grey-1);
}

/* section heading used between groups of stat tiles */
.rowhead {
    font-size: 13px; font-weight: 700; color: var(--navy);
    text-transform: uppercase; letter-spacing: .5px;
    margin: 4px 0 10px; padding-bottom: 6px;
    border-bottom: 2px solid var(--navy-soft);
}
.tiles + .rowhead { margin-top: 22px; }

/* the "waiting on X of Y departments" style progress badge */
.badge-progress { background: #eef2f7; color: #33475b; border-color: #d3dce6; }
