:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1d2733; --muted: #6b7785; --line: #dde3ea;
  --pri: #1f4e79; --pri-ink: #fff; --pri-soft: #e6eef7; --danger: #b3261e; --warn-bg: #fff4e0; --warn-ink: #7a4a00;
  --ok: #1e7b34; --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--pri); }
h1 { font-size: 1.35rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.25rem; margin: 0 0 .8rem; }
h3 { font-size: 1rem; margin: 1.4rem 0 .5rem; }
p { line-height: 1.45; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.pre { white-space: pre-wrap; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* forms & buttons */
label { display: block; margin: .7rem 0; font-size: .9rem; color: var(--muted); }
label input, label textarea, label select { display: block; width: 100%; margin-top: .25rem; color: var(--ink); }
input, textarea, select { font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
input:focus, textarea:focus { outline: 2px solid var(--pri-soft); border-color: var(--pri); }
textarea { resize: vertical; }
label.check { display: flex; gap: .5rem; align-items: center; color: var(--ink); }
label.check input { width: auto; margin: 0; }
.btn { font: inherit; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; }
.btn:hover { border-color: #b8c3cf; }
.btn.primary { background: var(--pri); color: var(--pri-ink); border-color: var(--pri); }
.btn.danger { color: var(--danger); border-color: #e7b8b5; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 1.1rem; cursor: pointer; padding: .3rem .5rem; color: var(--muted); }
.actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.actions.left { justify-content: flex-start; }
.notice { background: var(--warn-bg); color: var(--warn-ink); padding: .6rem .8rem; border-radius: 6px; }

/* auth card */
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.6rem; width: 100%; max-width: 440px; }
.logo { color: var(--pri); font-weight: 600; margin-bottom: .6rem; }

/* shell */
.top { position: sticky; top: 0; z-index: 5; display: flex; gap: .6rem; align-items: center; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; color: var(--pri); white-space: nowrap; }
#q { flex: 1; min-width: 0; max-width: 520px; margin-left: auto; }
.layout { display: flex; min-height: calc(100vh - 56px); }
.side { width: 230px; flex-shrink: 0; padding: 1rem .6rem; border-right: 1px solid var(--line); background: var(--panel); position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; }
.side a { display: flex; justify-content: space-between; padding: .5rem .7rem; border-radius: 6px; text-decoration: none; color: var(--ink); margin-bottom: 2px; }
.side a:hover { background: var(--bg); }
.side a.on { background: var(--pri-soft); color: var(--pri); font-weight: 600; }
.cnt { color: var(--muted); font-size: .85rem; font-weight: 400; }
.side-foot { margin-top: 1.5rem; padding: 0 .7rem; color: var(--muted); font-size: .8rem; }
main { flex: 1; padding: 1.2rem 1.6rem 4rem; max-width: 1000px; }
.only-mobile { display: none; }

.banner { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; text-decoration: none; color: var(--ink); }
.tile:hover { border-color: var(--pri); }
.tile-n { font-size: 1.5rem; font-weight: 600; color: var(--pri); }
.tile-l { font-size: .85rem; color: var(--muted); }
.sumline { margin-top: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem 1rem; }
.date-row { display: grid; grid-template-columns: 110px 110px 1fr; gap: .5rem; padding: .55rem .9rem; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); background: var(--panel); }
.date-row:last-child { border-bottom: 0; }
.date-row .w { color: var(--muted); }
.date-row.overdue .w, .date-row.overdue .d { color: var(--danger); font-weight: 600; }
.date-row.soon .w { color: var(--warn-ink); font-weight: 600; }

.seg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.adds { display: flex; gap: .4rem; flex-wrap: wrap; }
.seg-toggle { margin: .5rem 0 1rem; display: flex; gap: .4rem; }
.chip { font: inherit; font-size: .85rem; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: .3rem .8rem; cursor: pointer; }
.chip.on { background: var(--pri); color: #fff; border-color: var(--pri); }

.list { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.rec { border-bottom: 1px solid var(--line); }
.rec:last-child { border-bottom: 0; }
.rec-head { padding: .65rem 1rem; cursor: pointer; }
.rec-head:hover { background: #f8fafc; }
.rec.open .rec-head { background: var(--pri-soft); }
.rec-title { font-weight: 600; }
.rec-sub { color: var(--muted); font-size: .88rem; margin-top: .1rem; }
.rec-body { padding: .8rem 1rem 1rem; }
.fields { display: grid; grid-template-columns: 220px 1fr; gap: .35rem 1rem; }
.fl { color: var(--muted); font-size: .88rem; padding-top: .1rem; }
.fv { word-break: break-word; }
.copy { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .95rem; margin-left: .35rem; padding: 0 .2rem; }
.copy:hover { color: var(--pri); }
.rec-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
table.docs { width: 100%; border-collapse: collapse; margin-top: .8rem; background: var(--panel); }
table.docs th, table.docs td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; font-size: .92rem; }
table.docs th { color: var(--muted); font-weight: 500; }

/* modal */
#modal { position: fixed; inset: 0; background: rgba(20, 30, 45, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; overflow-y: auto; }
.dialog { background: var(--panel); border-radius: 12px; padding: 1.4rem; width: 100%; max-width: 460px; }
.dialog.wide { max-width: 820px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid .full { grid-column: 1 / -1; }
.lbl { font-size: .9rem; color: var(--muted); margin: .7rem 0 .3rem; }
.doc-head, .doc-row { display: grid; grid-template-columns: 1.1fr 1.2fr 1.6fr 150px 32px; gap: .4rem; align-items: center; }
.doc-head { font-size: .8rem; color: var(--muted); }
.doc-row { margin-bottom: .4rem; }
.doc-row input { width: 100%; min-width: 0; }
.menu { display: flex; flex-direction: column; gap: .5rem; }
.row-line { display: flex; justify-content: space-between; align-items: center; padding: .5rem .8rem; border-bottom: 1px solid var(--line); }
.row-line:last-child { border-bottom: 0; }
.rkey { font-size: 1.15rem; letter-spacing: .04em; background: var(--bg); border: 1px dashed var(--pri); border-radius: 8px; padding: .9rem; text-align: center; word-break: break-all; user-select: all; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0 .4rem; }

#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(150%); background: #22303f; color: #fff; padding: .7rem 1.1rem; border-radius: 8px; z-index: 100; max-width: 90vw; transition: transform .2s; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

#print { display: none; }

/* phone-size screens */
@media (max-width: 760px) {
  .only-mobile { display: inline-block; }
  .brand { display: none; }
  #q { margin-left: 0; }
  .top .btn[data-act=print] { display: none; }
  .top { gap: .4rem; padding: .5rem .6rem; }
  .side { position: fixed; left: 0; top: 52px; z-index: 6; height: calc(100vh - 52px); transform: translateX(-100%); transition: transform .2s; box-shadow: 2px 0 10px rgba(0,0,0,.1); }
  body.side-open .side { transform: none; }
  main { padding: 1rem; }
  .fields { grid-template-columns: 1fr; gap: .1rem; }
  .fl { margin-top: .5rem; }
  .grid { grid-template-columns: 1fr; }
  .doc-head { display: none; }
  .doc-row { grid-template-columns: 1fr 1fr; border: 1px solid var(--line); padding: .4rem; border-radius: 6px; }
  .date-row { grid-template-columns: 1fr 1fr; }
  .date-row .t { grid-column: 1 / -1; }
}

/* printing */
@media print {
  body.printing #root > *:not(#print), body.printing .top, body.printing .layout, body.printing #toast, body.printing #modal { display: none !important; }
  body.printing #print { display: block; font-size: 11pt; }
  #print h1 { font-size: 16pt; }
  #print h2 { font-size: 13pt; border-bottom: 1px solid #999; margin-top: 14pt; }
  #print h3 { font-size: 11pt; margin: 8pt 0 3pt; }
  #print h3 small { font-weight: 400; color: #555; }
  #print table { border-collapse: collapse; width: 100%; }
  #print th, #print td { text-align: left; vertical-align: top; padding: 2pt 4pt; border-bottom: 1px solid #ddd; }
  #print th { width: 32%; font-weight: 500; color: #444; }
  #print .p-rec { break-inside: avoid; }
}
