:root {
  --accent: #1f4e79;
  --accent-dark: #163a5c;
  --accent-light: #e8f0f8;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1c2431;
  --muted: #6b7684;
  --border: #dfe4ea;
  --danger: #c0392b;
  --success: #1e8449;
  --warning: #b9770e;
  --sidebar-w: 240px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 600; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 .75rem; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; } .mr { margin-right: .5rem; }
.right { text-align: right; } .center { text-align: center; }
.flex { display: flex; gap: .75rem; align-items: center; } .flex.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.between { justify-content: space-between; }
.hidden { display: none !important; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; background: linear-gradient(160deg, var(--accent) 0%, var(--accent-dark) 60%, #0f2540 100%); }
.auth-card { width: 100%; max-width: 440px; background: var(--card); border-radius: 16px; padding: 2rem; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand .logo { width: 56px; height: 56px; border-radius: 14px; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 700; margin-bottom: .5rem; }
.auth-brand h1 { font-size: 20px; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.auth-tabs button { flex: 1; background: none; border: none; padding: .6rem; font-size: 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.auth-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.auth-foot { text-align: center; margin-top: 1rem; font-size: 12px; color: var(--muted); }
.lang-switch { position: fixed; top: 12px; right: 16px; }
.lang-switch button, .lang-btn { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 20px; padding: 4px 12px; cursor: pointer; font-size: 12px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--accent-dark); color: #fff; display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 20; transition: transform .2s; }
.sidebar .brand { padding: 1.1rem 1.25rem; font-weight: 700; font-size: 16px; border-bottom: 1px solid rgba(255,255,255,.1); display: flex; align-items: center; gap: .6rem; }
.sidebar .brand .logo { width: 32px; height: 32px; border-radius: 8px; background: #fff; color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; flex-shrink: 0; }
.sidebar .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar nav { flex: 1; padding: .75rem 0; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: .7rem; padding: .6rem 1.25rem; color: rgba(255,255,255,.8); font-size: 14px; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #fff; }
.sidebar nav a .ico { width: 20px; text-align: center; font-size: 16px; opacity: .9; }
.sidebar nav a .cnt { margin-left: auto; background: #e74c3c; color: #fff; font-size: 11px; border-radius: 10px; padding: 0 7px; min-width: 18px; text-align: center; font-weight: 600; }
.sidebar .sb-section { padding: .9rem 1.25rem .3rem; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.45); }
.sidebar .user { padding: .9rem 1.25rem; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.sidebar .user .name { font-weight: 600; }
.sidebar .user .role { color: rgba(255,255,255,.6); font-size: 12px; }
.sidebar .user .links { margin-top: .5rem; display: flex; gap: .75rem; }
.sidebar .user .links a { color: rgba(255,255,255,.75); font-size: 12px; cursor: pointer; }
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
.topbar { background: var(--card); border-bottom: 1px solid var(--border); padding: .7rem 1.5rem; display: flex; align-items: center; gap: 1rem; position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.topbar .menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; cursor: pointer; }
.content { padding: 1.5rem; max-width: 1200px; }
.bell { position: relative; background: none; border: 1px solid var(--border); border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 16px; }
.bell .cnt { position: absolute; top: -4px; right: -4px; background: #e74c3c; color: #fff; font-size: 10px; border-radius: 10px; padding: 0 5px; min-width: 16px; font-weight: 700; }
.notif-panel { position: absolute; right: 1.5rem; top: 52px; width: 340px; max-height: 420px; overflow-y: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.15); z-index: 30; }
.notif-panel .n { padding: .6rem .9rem; border-bottom: 1px solid var(--border); font-size: 13px; cursor: pointer; }
.notif-panel .n.unread { background: var(--accent-light); }
.notif-panel .n .t { color: var(--muted); font-size: 11px; }
.notif-panel .empty { padding: 1.5rem; text-align: center; color: var(--muted); }

/* ---------- components ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card h2, .card h3 { display: flex; align-items: center; gap: .5rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 1.25rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); cursor: pointer; transition: transform .1s; }
.stat:hover { transform: translateY(-2px); }
.stat .v { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat .l { color: var(--muted); font-size: 12px; }
.stat.warn .v { color: var(--warning); }
.stat.danger .v { color: var(--danger); }
.stat.ok .v { color: var(--success); }

.btn { display: inline-flex; align-items: center; gap: .4rem; background: var(--accent); color: #fff; border: 1px solid var(--accent); border-radius: 7px; padding: .5rem .95rem; font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--accent-dark); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--accent); }
.btn.secondary:hover { background: var(--accent-light); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: #f0f2f5; }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #fdecea; }
.btn.success { background: var(--success); border-color: var(--success); }
.btn.sm { padding: .3rem .65rem; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

.form-row { margin-bottom: .9rem; }
.form-row label, .lbl { display: block; font-size: 12.5px; font-weight: 600; color: #3c4653; margin-bottom: .3rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .5rem 1rem; }
.form-grid .full { grid-column: 1 / -1; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], input[type=url], select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 7px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,78,121,.15); }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: flex-start; gap: .6rem; font-weight: normal; }
.check input { margin-top: 3px; }
.help { font-size: 12px; color: var(--muted); margin-top: .25rem; }
.err { color: var(--danger); font-size: 13px; margin: .5rem 0; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: .6rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:hover td { background: #fafbfd; }
.table-wrap { overflow-x: auto; }
tr.clickable { cursor: pointer; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: #eef1f5; color: #4b5563; white-space: nowrap; }
.badge.blue { background: var(--accent-light); color: var(--accent); }
.badge.green { background: #e3f5e9; color: var(--success); }
.badge.red { background: #fdecea; color: var(--danger); }
.badge.orange { background: #fff3e0; color: var(--warning); }
.badge.new { background: #e74c3c; color: #fff; }

.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: .25rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .65rem 0; border-bottom: 1px solid var(--border); display: flex; gap: .75rem; align-items: center; }
.list li:last-child { border-bottom: none; }
.list .ico { font-size: 20px; width: 28px; text-align: center; }
.list .body { flex: 1; min-width: 0; }
.list .title { font-weight: 500; }
.list .sub { color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-size: 13.5px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a .cnt { background: #e74c3c; color: #fff; font-size: 10px; border-radius: 8px; padding: 0 5px; margin-left: 4px; }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; background: #fafbfc; }
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }
.dropzone .big { font-size: 32px; }
.file-list { margin-top: .5rem; font-size: 13px; }
.file-list div { padding: .2rem 0; }
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: .5rem; }
.progress span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* messages */
.msg-layout { display: grid; grid-template-columns: 320px 1fr; gap: 1.25rem; min-height: 60vh; }
.thread-list { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.thread-list .th { padding: .75rem .9rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.thread-list .th:hover { background: #fafbfd; }
.thread-list .th.active { background: var(--accent-light); }
.thread-list .th .s { font-weight: 600; display: flex; justify-content: space-between; gap: .5rem; }
.thread-list .th .p { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-view { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 60vh; }
.thread-view .head { padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); }
.thread-view .msgs { flex: 1; padding: 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: .75rem; max-height: 55vh; }
.bubble { max-width: 78%; padding: .6rem .85rem; border-radius: 12px; background: #eef1f5; white-space: pre-wrap; word-break: break-word; }
.bubble.me { align-self: flex-end; background: var(--accent); color: #fff; }
.bubble .meta { font-size: 11px; opacity: .7; margin-top: .25rem; }
.thread-view .composer { padding: .75rem 1rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; align-items: flex-end; }
.thread-view .composer textarea { min-height: 44px; }

/* checklists / questionnaires */
.cl-item { display: flex; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.cl-item:last-child { border-bottom: none; }
.cl-item input[type=checkbox] { width: 18px; height: 18px; margin-top: 2px; }
.cl-item .body { flex: 1; }
.cl-item.done .label { text-decoration: line-through; color: var(--muted); }
.cl-item .na { font-size: 12px; color: var(--muted); white-space: nowrap; }
.q-item { padding: .8rem 0; border-bottom: 1px solid var(--border); }
.q-item:last-child { border-bottom: none; }
.q-item .ql { font-weight: 500; margin-bottom: .4rem; }
.q-item .req { color: var(--danger); }
.radio-row { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.radio-row label { font-weight: normal; display: inline-flex; gap: .35rem; align-items: center; }

/* signature pad */
.sigpad { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; touch-action: none; width: 100%; height: 180px; display: block; }
.sig-img { max-height: 70px; border: 1px solid var(--border); border-radius: 6px; background: #fff; padding: 4px; }
.pdf-frame { width: 100%; height: 60vh; border: 1px solid var(--border); border-radius: var(--radius); background: #555; }

/* invoice */
.inv-total { font-size: 20px; font-weight: 700; color: var(--accent); }
.line-items input { margin-bottom: .3rem; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal { background: var(--card); border-radius: 14px; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; box-shadow: 0 25px 60px rgba(0,0,0,.35); }
.modal.wide { max-width: 900px; }
.modal .m-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal .m-head h3 { margin: 0; }
.modal .m-body { padding: 1.25rem; }
.modal .m-foot { padding: .9rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }
.modal .x { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: #1c2431; color: #fff; padding: .7rem 1rem; border-radius: 8px; font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: fadein .2s; max-width: 360px; }
.toast.error { background: var(--danger); } .toast.success { background: var(--success); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .4rem 0 .4rem 1.1rem; border-left: 2px solid var(--border); position: relative; font-size: 13px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .t { color: var(--muted); font-size: 11.5px; }

.kv { display: grid; grid-template-columns: 180px 1fr; gap: .35rem 1rem; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.25rem 0 .5rem; padding-bottom: .3rem; border-bottom: 1px solid var(--border); }
.section-title:first-child { margin-top: 0; }
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 13.5px; }
.alert.info { background: var(--accent-light); color: var(--accent-dark); }
.alert.warn { background: #fff6e5; color: #8a5a00; }
.alert.success { background: #e3f5e9; color: var(--success); }
.search { max-width: 340px; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 15; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .overlay.show { display: block; }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-block; }
  .msg-layout { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
}
@media print { .sidebar, .topbar, .btn { display: none !important; } .main { margin: 0; } }
