:root {
  --navy: #0F2A44;
  --navy-2: #1B3B5C;
  --teal: #0F8B8D;
  --teal-soft: #E3F4F3;
  --amber: #B7791F;
  --amber-soft: #FCF1DE;
  --red: #A32D2D;
  --red-soft: #FCEBEB;
  --green: #2F6B1E;
  --green-soft: #EAF3DE;
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --text: #16202B;
  --muted: #5E6B78;
  --line: #DFE3E8;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body.zx-dark {
  --bg: #0E141B;
  --surface: #17202A;
  --text: #E6EBF0;
  --muted: #9AA7B4;
  --line: #2A3643;
  --teal-soft: #12302F;
  --amber-soft: #3A2C12;
  --red-soft: #3B1A1A;
  --green-soft: #1C2E14;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--teal); }
h1 { font-size: 24px; margin: 0 0 6px; font-weight: 600; }
h2 { font-size: 18px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 600; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* top bar */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 56px; }
.brand { display: flex; align-items: baseline; gap: 10px; color: #fff; text-decoration: none; white-space: nowrap; }
.brand strong { font-size: 17px; letter-spacing: .2px; }
.brand span { font-size: 12px; color: #A9C3D6; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; color: #C9D6E2; }
.topbar form { margin: 0; }
.linkbtn { background: none; border: 0; color: #C9D6E2; font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; padding: 0; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 32px 20px 64px; }
.narrow { max-width: 460px; margin: 64px auto; padding: 0 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }

/* forms */
label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 4px; }
input[type=text], input[type=email], input[type=date], input[type=file], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 160px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; font-size: 14px; }
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border-radius: 8px; border: 1px solid var(--teal); background: var(--teal); color: #fff; padding: 9px 16px; text-decoration: none; }
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.notice { background: var(--teal-soft); border: 1px solid var(--teal); color: var(--text); padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; }
.warn { background: var(--amber-soft); border: 1px solid var(--amber); padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; }
.devlink { word-break: break-all; background: var(--amber-soft); border: 1px dashed var(--amber); padding: 10px; border-radius: 8px; font-size: 13px; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.pill.open { background: var(--amber-soft); color: var(--amber); }
.pill.answered { background: var(--teal-soft); color: var(--teal); }
.pill.resolved { background: var(--green-soft); color: var(--green); }
.pill.off { background: var(--red-soft); color: var(--red); }
.pill.neutral { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

.readout-list a.item { display: flex; justify-content: space-between; gap: 16px; padding: 16px 18px; text-decoration: none; color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; }
.readout-list a.item:hover { border-color: var(--teal); }

/* viewer */
.viewer-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .title { font-weight: 600; margin-right: 8px; }
.toolbar .title small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.toolbar select { width: auto; padding: 6px 8px; font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; padding: 6px 11px; background: var(--surface); color: var(--text); border: 0; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed=true] { background: var(--navy); color: #fff; }
.seg button[disabled] { opacity: .45; cursor: not-allowed; }
.toolbar .spacer { flex: 1; }
.versionbar { padding: 8px 16px; font-size: 13px; background: var(--amber-soft); border-bottom: 1px solid var(--line); }
.versionbar.info { background: var(--teal-soft); }
.main { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; overflow: auto; background: var(--bg); padding: 14px; position: relative; }
.sheet { position: relative; margin: 0 auto; box-shadow: 0 1px 4px rgba(0,0,0,.12); border-radius: 2px; overflow: hidden; background: #fff; }
.sheet iframe { position: absolute; left: 0; top: 0; border: 0; transform-origin: 0 0; background: #fff; }
.pagetabs { display: flex; gap: 4px; padding: 6px 16px 0; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.pagetabs button { border: 1px solid transparent; border-bottom: 0; background: none; padding: 7px 12px; border-radius: 6px 6px 0 0; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.pagetabs button[aria-selected="true"] { background: var(--bg); color: var(--text); border-color: var(--line); font-weight: 600; margin-bottom: -1px; }
.pagetabs button .n { display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px; border-radius: 9px; background: var(--teal); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 320px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12); padding: 6px; }
.menu-list .item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 6px; }
.menu-list .item:hover { background: var(--bg); }
.menu-list .item .name { flex: 1; font-size: 13px; }
.menu-list .item .name small { display: block; color: var(--muted); font-size: 11.5px; }
.menu-list a { font-size: 12.5px; }
.menu-list .note { font-size: 12px; color: var(--muted); padding: 6px 8px 2px; }
.panel { width: 380px; border-left: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.panel[hidden] { display: none; }
.panel header { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.panel .lock { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.panel .filters { display: flex; gap: 6px; margin-top: 10px; }
.panel .filters button { font: inherit; font-size: 12px; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.panel .filters button[aria-pressed=true] { background: var(--navy); color: #fff; border-color: var(--navy); }
.panel .list { flex: 1; overflow-y: auto; padding: 12px 16px; }
.panel .compose { border-top: 1px solid var(--line); padding: 12px 16px; }
.target { font-size: 13px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.target strong { font-weight: 600; }
.thread { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.thread.focus { border-color: var(--teal); box-shadow: 0 0 0 2px var(--teal-soft); }
.thread .on { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
.thread .on a { cursor: pointer; }
.msg { margin: 6px 0; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg .by { font-size: 12px; color: var(--muted); display: block; white-space: normal; }
.msg.reply { border-left: 3px solid var(--teal); padding-left: 9px; margin-left: 4px; }
.msg.reply.client { border-left-color: var(--line); }
.thread .actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.thread textarea { min-height: 54px; font-size: 14px; margin-top: 6px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 30px 10px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 50; }
.toast[hidden] { display: none; }
.error { color: var(--red); font-size: 13px; margin-top: 6px; }

@media (max-width: 900px) {
  .panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(100%, 400px); z-index: 20; box-shadow: -4px 0 16px rgba(0,0,0,.15); }
  .toolbar .title { width: 100%; }
}
