/* eTech Office Management System */
:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1c2333;
  --muted: #6b7590;
  --line: #e2e7f0;
  --brand: #1f5fbf;
  --brand-dark: #17488f;
  --green: #157f4a;
  --green-bg: #e4f5ec;
  --red: #bb2231;
  --red-bg: #fdeaec;
  --amber: #9a6200;
  --amber-bg: #fdf1dc;
  --grey-bg: #eef1f6;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }
p { margin: 0 0 10px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; flex: 0 0 210px; background: #0f1b2e; color: #c8d3e6;
  padding: 0 0 30px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.logo { padding: 16px 16px 14px; border-bottom: 1px solid #1e2d47; }
.logo a { color: #fff; font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.logo a:hover { text-decoration: none; }
.mark {
  background: var(--brand); color: #fff; width: 26px; height: 26px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700;
}
.nav-group {
  padding: 14px 16px 5px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .09em; color: #6d7f9c; font-weight: 600;
}
.nav-item { display: block; padding: 7px 16px; color: #c8d3e6; font-size: 13.5px; border-left: 3px solid transparent; }
.nav-item:hover { background: #172741; color: #fff; text-decoration: none; }
.nav-item.active { background: #172c4a; color: #fff; border-left-color: var(--brand); font-weight: 600; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 11px 22px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-weight: 600; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.who { color: var(--muted); }
a.who:hover { color: var(--ink); text-decoration: none; }
.who .role {
  background: var(--grey-bg); border-radius: 20px; padding: 2px 9px;
  font-size: 11px; margin-left: 5px; color: var(--ink);
}
.bell { position: relative; color: var(--ink); display: inline-flex; align-items: center; gap: 5px; }
.bell svg { display: block; }
.bell.has-unread svg { color: var(--red); }

/* Install-as-app button, shown only when the browser offers installation. */
#install-app { display: none; }
.bell .dot {
  background: var(--red); color: #fff; border-radius: 20px; font-size: 11px;
  padding: 1px 6px; margin-left: 4px; font-weight: 600;
}
main { padding: 20px 22px 60px; max-width: 1180px; }
main.wide { max-width: none; }
.plain-page { max-width: 420px; margin: 70px auto; padding: 0 16px; }

/* ---------- headers, cards ---------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px;
}
.card.pad0 { padding: 0; overflow: hidden; }
.card-head {
  padding: 13px 18px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.card-head h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; }
.tile-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 21px; font-weight: 600; margin-top: 5px; }
.tile-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.tile.good .tile-value { color: var(--green); }
.tile.bad .tile-value { color: var(--red); }
.tile.warn .tile-value { color: var(--amber); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.list th, table.list td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th {
  background: #f8fafd; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap;
}
table.list tbody tr:hover { background: #f9fbfe; }
table.list tr.is-urgent td { background: #fff7f7; }
table.list tr.is-urgent:hover td { background: #ffeff0; }
table.list td.num, table.list th.num { text-align: right; white-space: nowrap; }
.empty { padding: 26px; text-align: center; color: var(--muted); }
tfoot td { font-weight: 600; background: #f8fafd; }

/* ---------- forms ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; color: #38445f; }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=number],
input[type=datetime-local], input[type=month], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #ccd4e2; border-radius: 7px;
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd4f5; border-color: var(--brand); }
textarea { min-height: 72px; resize: vertical; }
.field { margin-bottom: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 0 16px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 700px) { .form-grid.two { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.check { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13px; }
.check input { width: auto; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 16px; }
legend { font-weight: 600; font-size: 13px; padding: 0 6px; color: #38445f; }

/* ---------- buttons ---------- */
.btn, .btn-outline, .btn-plain, .btn-danger {
  display: inline-block; padding: 8px 14px; border-radius: 7px; font-size: 13.5px;
  font-weight: 600; cursor: pointer; border: 1px solid transparent; font-family: inherit;
}
.btn { background: var(--brand); color: #fff; }
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn-outline { background: #fff; color: var(--brand); border-color: #b9cdec; }
.btn-outline:hover { background: #f2f7ff; text-decoration: none; }
.btn-plain { background: transparent; color: var(--muted); }
.btn-plain:hover { color: var(--ink); text-decoration: none; }
.btn-danger { background: #fff; color: var(--red); border-color: #f0bfc5; }
.btn-danger:hover { background: var(--red-bg); text-decoration: none; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
button:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- badges & flags ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px;
  font-weight: 600; white-space: nowrap;
}
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red   { background: var(--red-bg);   color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.grey  { background: var(--grey-bg);  color: #4a5670; }
.badge.urgent { background: var(--red); color: #fff; letter-spacing: .04em; }
.badge.high  { background: var(--amber-bg); color: var(--amber); }
.badge.low   { background: var(--grey-bg); color: var(--muted); }
.flag { color: var(--red); font-size: 15px; margin-right: 4px; }
.bs { color: var(--muted); font-size: 11.5px; white-space: nowrap; }

/* ---------- flash ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; font-weight: 500; }
.flash.ok   { background: var(--green-bg); color: var(--green); }
.flash.err  { background: var(--red-bg);   color: var(--red); }
.flash.warn { background: var(--amber-bg); color: var(--amber); }

/* ---------- filters ---------- */
.filters {
  display: flex; gap: 9px; flex-wrap: wrap; align-items: flex-end;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 15px;
}
.filters .field { margin: 0; min-width: 140px; }
.filters input, .filters select { min-width: 130px; }

/* ---------- progress ---------- */
.bar { background: var(--grey-bg); border-radius: 20px; height: 8px; overflow: hidden; min-width: 90px; }
.bar span { display: block; height: 100%; background: var(--brand); border-radius: 20px; }
.bar.good span { background: var(--green); }
.bar.bad span  { background: var(--red); }
.bar.warn span { background: #e0a020; }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ''; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--brand); border: 2px solid #fff;
}
.timeline li.done::before { background: var(--green); }
.timeline .t-when { font-size: 12px; color: var(--muted); }
.timeline .t-what { font-weight: 600; }

/* ---------- items editor ---------- */
table.items { width: 100%; border-collapse: collapse; }
table.items th { font-size: 11.5px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 6px; }
table.items td { padding: 4px 6px; vertical-align: top; }
table.items input { padding: 6px 8px; }
table.items .col-sn { width: 34px; color: var(--muted); text-align: center; padding-top: 12px; }
table.items .col-qty { width: 90px; }
table.items .col-unit { width: 90px; }
table.items .col-rate { width: 125px; }
table.items .col-amt { width: 125px; text-align: right; padding-top: 12px; font-weight: 600; }
table.items .col-x { width: 34px; }
.totals { margin-left: auto; width: 320px; font-size: 14px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; font-size: 17px; font-weight: 700; }

/* ---------- chat ---------- */
.chat-wrap { display: grid; grid-template-columns: 270px 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .chat-wrap { grid-template-columns: 1fr; } }
.chat-threads { max-height: 380px; overflow-y: auto; }
.chat-thread { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.chat-thread:hover { background: #f7f9fd; text-decoration: none; }
.chat-thread.active { background: #eef4fd; border-left: 3px solid var(--brand); }
.chat-thread .ct-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-thread .dot { background: var(--red); color: #fff; border-radius: 20px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.chat-thread .ct-prev { font-size: 12.5px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread .ct-when { font-size: 11px; color: var(--muted); margin-top: 2px; }
.chat-new { padding: 12px 14px; border-top: 1px solid var(--line); }
.chat-messages { height: 420px; overflow-y: auto; padding: 14px 16px; background: #f8fafd; }
.chat-day { text-align: center; font-size: 11.5px; color: var(--muted); margin: 10px 0 6px; }
.chat-msg { max-width: 74%; margin-bottom: 10px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 11px; }
.chat-msg.mine { margin-left: auto; background: #e8f1fe; border-color: #cfe0fa; }
.chat-msg .cm-who { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.chat-msg .cm-at { font-weight: 400; margin-left: 6px; }
.chat-msg .cm-body { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.chat-send { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-send textarea { flex: 1; min-height: 44px; }

/* ---------- letterheads ---------- */
.lh { margin-bottom: 4px; }
.lh-text { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.lh-left { display: flex; gap: 12px; align-items: flex-start; }
.lh-logo { max-height: 64px; max-width: 120px; }
.lh-banner { display: block; width: 100%; max-height: 150px; object-fit: contain; }
.lh-right { text-align: right; }
.lh-rule { height: 3px; margin-top: 10px; border-radius: 2px; }
.lh-foot { margin-top: 26px; padding-top: 8px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted); text-align: center; }

/* ---------- letters, signatures and stamps ---------- */
.letter-body { line-height: 1.85; font-size: 14.5px; white-space: pre-wrap; }
.sign-block { position: relative; display: inline-block; min-width: 240px; text-align: left; }
.sign-block .signature { display: block; max-height: 70px; max-width: 220px; margin-bottom: -6px; }
.sign-block .sign-space { height: 52px; }
.sign-block .sign-rule { border-top: 1px solid var(--ink); width: 220px; margin-bottom: 4px; }
.sign-block .sign-name { font-weight: 600; font-size: 13.5px; }
.sign-block .sign-title { font-size: 12.5px; color: var(--muted); }
.sign-block .stamp {
  position: absolute; right: -50px; top: -18px; max-height: 110px; max-width: 130px;
  opacity: .82; pointer-events: none;
}
.mark-preview { max-height: 70px; max-width: 200px; border: 1px solid var(--line);
  border-radius: 6px; padding: 6px; background: #fff; }

/* ---------- print documents ---------- */
.doc { background: #fff; padding: 34px 38px; max-width: 820px; margin: 0 auto; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--ink); padding-bottom: 14px; margin-bottom: 18px; }
.doc-head .co-name { font-size: 20px; font-weight: 700; }
.doc-title { font-size: 24px; font-weight: 700; text-align: right; }
.doc table.items th { border-bottom: 1px solid var(--line); }
.doc table.items td { border-bottom: 1px solid #f0f2f7; }
.doc-parties { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .doc { padding: 0; max-width: none; }
  .card { border: none; padding: 0; }
}
