* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #68788c;
  --line: #e3e8ef;
  --accent: #c0392b;
  --accent-dark: #96281b;
  --green: #1e8e4e;
  --amber: #b7791f;
  --sidebar: #182233;
  --sidebar-ink: #b9c4d3;
}
body { font-family: -apple-system, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--sidebar); color: var(--sidebar-ink); flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid #2a3850; }
.brand-icon { font-size: 26px; }
.brand-name { color: #fff; font-weight: 700; font-size: 14px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: #7f8ea5; }
.sidebar nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: var(--sidebar-ink); text-decoration: none; padding: 9px 12px; border-radius: 8px; font-size: 13.5px; }
.sidebar nav a:hover { background: #223046; color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; }

main { flex: 1; padding: 24px 28px; max-width: 1200px; }
h1 { font-size: 21px; margin-bottom: 4px; }
.page-sub { color: var(--muted); margin-bottom: 20px; font-size: 13px; }
h2 { font-size: 15px; margin: 18px 0 10px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.card .label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.card .value { font-size: 24px; font-weight: 700; }
.card .value small { font-size: 13px; font-weight: 400; color: var(--muted); }
.card.accent .value { color: var(--accent); }
.card.green .value { color: var(--green); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.panel h2 { margin-top: 0; }

table { width: 100%; border-collapse: collapse; background: var(--card); }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge.green { background: #e3f5eb; color: var(--green); }
.badge.red { background: #fdecea; color: var(--accent); }
.badge.amber { background: #fdf3e0; color: var(--amber); }
.badge.gray { background: #eef1f5; color: var(--muted); }

form.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; align-items: end; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
input, select, textarea { padding: 8px 10px; border: 1px solid #cdd5e0; border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(192,57,43,.25); border-color: var(--accent); }

button { cursor: pointer; border: none; border-radius: 8px; padding: 9px 16px; font-size: 13.5px; font-weight: 600; font-family: inherit; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.small { padding: 4px 10px; font-size: 12px; }
button.link { background: none; color: var(--accent); padding: 2px 6px; font-weight: 600; }
button.link.gray { color: var(--muted); }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; }
.spacer { flex: 1; }

.bar { height: 8px; border-radius: 5px; background: #edf0f4; overflow: hidden; min-width: 80px; }
.bar > div { height: 100%; background: var(--green); border-radius: 5px; }
.bar > div.warn { background: var(--amber); }
.bar > div.full { background: var(--accent); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.empty { text-align: center; color: var(--muted); padding: 28px; }

/* auth */
#auth:empty { display: none; }
#auth { position: fixed; inset: 0; background: var(--sidebar); z-index: 200; display: flex; align-items: center; justify-content: center; }
.auth-box { background: #fff; border-radius: 16px; padding: 34px; width: min(400px, 92vw); }
.auth-box .brand { padding: 0 0 20px; border-bottom: none; }
.auth-box .brand-name { color: var(--ink); font-size: 18px; }
.auth-box form { display: flex; flex-direction: column; gap: 12px; }
.auth-box button { margin-top: 6px; padding: 11px; }
.auth-err { color: var(--accent); font-size: 13px; min-height: 18px; }

.sidebar-user { margin-top: auto; padding: 14px 16px; border-top: 1px solid #2a3850; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sidebar-user .who { flex: 1; }
.sidebar-user .who b { color: #fff; display: block; }
.sidebar-user .who small { color: #7f8ea5; text-transform: capitalize; }
.sidebar { display: flex; flex-direction: column; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,36,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; padding: 22px; width: min(560px, 92vw); max-height: 88vh; overflow-y: auto; }
.modal h2 { margin: 0 0 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* toast */
#toast { position: fixed; bottom: 22px; right: 22px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast-msg { background: #1c2733; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: fadein .2s; }
.toast-msg.error { background: var(--accent); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } }

/* print */
#print-area { display: none; }
@media print {
  #toast, #modal-root, #auth, .sidebar, .toolbar, button { display: none !important; }
  main { padding: 0; max-width: none; }
  body.printing-doc .layout { display: none !important; }
  body.printing-doc #print-area { display: block; font-size: 13px; color: #000; }
  .doc { max-width: 700px; margin: 0 auto; }
  .doc-head { text-align: center; border-bottom: 2px solid #000; padding-bottom: 10px; margin-bottom: 14px; }
  .doc-head h1 { font-size: 20px; }
  .doc-title { font-size: 15px; font-weight: 700; margin: 10px 0; text-transform: uppercase; letter-spacing: .06em; }
  .doc table { width: 100%; border-collapse: collapse; margin: 10px 0; }
  .doc th, .doc td { border: 1px solid #444; padding: 6px 8px; text-align: left; }
  .doc .meta { display: flex; justify-content: space-between; margin: 6px 0; }
  .doc .sign { display: flex; justify-content: space-between; margin-top: 60px; }
  .doc .sign div { border-top: 1px solid #000; padding-top: 4px; width: 180px; text-align: center; }
}
