:root {
  --navy: #0B2340;
  --navy-2: #081A30;
  --blue: #0B4F8A;
  --blue-2: #2F7BD8;
  --bg: #F5F3EE;
  --panel: #FFFFFF;
  --line: #E4E0D8;
  --text: #0E1726;
  --muted: #5E6E86;
  --green: #1F9D55;
  --red: #C0392B;
  --amber: #B7791F;
  --radius: 10px;
  --mono: ui-monospace, Menlo, Consolas, monospace;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); -webkit-font-smoothing: antialiased; font-size: 15px; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--blue); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: #08365f; }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13.5px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
input[type=text], input[type=password], input[type=date], input[type=url], input:not([type]), select, textarea {
  border: 1px solid #D5D0C6; border-radius: 7px; padding: 9px 11px; background: #fff; font-weight: 400; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,123,216,.35); border-color: var(--blue-2); }
textarea { resize: vertical; line-height: 1.5; }
.form-error { color: var(--red); margin: 0; font-size: 14px; }
.hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--navy); padding: 16px; }
.login-card { background: #fff; border-radius: 14px; padding: 36px 34px 28px; width: 100%; max-width: 380px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.login-card h1 { margin: 18px 0 4px; font-size: 22px; letter-spacing: -.01em; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
.login-logo { height: 26px; width: auto; display: block; }
.login-foot { font-size: 12.5px; margin: 20px 0 0; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.sidebar { background: var(--navy); color: #C6D2E4; display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; color: #fff; font-weight: 600; }
.sidebar .brand img { height: 18px; filter: brightness(0) invert(1); }
.sidebar .brand span { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: #9FB0CC; font-family: var(--mono); }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent; border: 0; color: #C6D2E4; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14.5px; font-weight: 500; }
.nav-btn:hover { background: #12305A; color: #fff; }
.nav-btn.active { background: #17406F; color: #fff; }
.nav-btn .ico { width: 18px; text-align: center; opacity: .9; }
.sidebar .spacer { flex: 1; }
.sidebar .who { font-size: 13px; padding: 10px 12px; border-top: 1px solid #17304F; margin-top: 8px; }
.sidebar .who strong { color: #fff; display: block; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 22px; background: #fff; border-bottom: 1px solid var(--line); min-height: 60px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; letter-spacing: -.01em; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 5px 10px; border-radius: 999px; background: #EEF2F7; color: var(--muted); cursor: pointer; border: 0; }
.chip.warn { background: #FFF4E0; color: #8A5A00; }
.chip.ok { background: #E7F6EE; color: #17663B; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.view { flex: 1; min-height: 0; overflow: auto; }
.view-pad { padding: 24px; max-width: 1100px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel + .panel { margin-top: 18px; }
.panel h2 { font-size: 16px; margin: 0 0 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }

/* ---------- chat ---------- */
.chat-layout { display: grid; grid-template-columns: 230px minmax(360px, 1fr) minmax(0, 1.1fr); height: 100%; }
.chat-layout.no-preview { grid-template-columns: 230px 1fr 0; }
.conv-list { border-right: 1px solid var(--line); background: #FBFAF7; overflow: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.conv-item { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 9px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item:hover { background: #EFECE5; }
.conv-item.active { background: #E3E9F2; font-weight: 600; }
.conv-item small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }
.chat-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--line); background: #fff; }
.messages { flex: 1; overflow: auto; padding: 22px 22px 8px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 100%; line-height: 1.55; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--blue); color: #fff; padding: 10px 14px; border-radius: 14px 14px 4px 14px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .by { display: block; font-size: 11px; opacity: .75; margin-bottom: 2px; }
.msg.assistant { align-self: stretch; }
.msg.assistant .text p { margin: 0 0 10px; }
.msg.assistant .text p:last-child { margin-bottom: 0; }
.msg.assistant .text pre { background: #0E1726; color: #E4EAF3; padding: 12px; border-radius: 8px; overflow: auto; font-size: 13px; }
.msg.assistant .text code { font-family: var(--mono); font-size: 13px; background: #F1F4F8; padding: 1px 4px; border-radius: 4px; }
.msg.assistant .text pre code { background: none; padding: 0; }
.msg.assistant .text ul, .msg.assistant .text ol { margin: 0 0 10px; padding-left: 22px; }
.msg.assistant .text table { border-collapse: collapse; margin: 0 0 10px; font-size: 14px; }
.msg.assistant .text th, .msg.assistant .text td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.msg.assistant .text th { background: #F6F4EF; }
.msg.assistant .text h3, .msg.assistant .text h4 { margin: 12px 0 6px; font-size: 15.5px; }
.steps { margin: 0 0 10px; font-size: 13px; color: var(--muted); border-left: 2px solid var(--line); padding-left: 10px; }
.steps summary { cursor: pointer; user-select: none; }
.steps ol { margin: 6px 0 0; padding-left: 18px; }
.steps li.err { color: var(--red); }
.step-live { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.spinner { width: 13px; height: 13px; border: 2px solid #C9D4E3; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.commit-card { margin-top: 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; background: #F3F8F4; border: 1px solid #CFE8D8; color: #17663B; border-radius: 8px; padding: 8px 10px; }
.commit-card .files { color: var(--muted); flex: 1; min-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-error { margin-top: 8px; color: var(--red); font-size: 13.5px; }
.composer { padding: 12px 16px 16px; border-top: 1px solid var(--line); background: #fff; }
.composer-box { display: flex; gap: 8px; align-items: flex-end; border: 1px solid #D5D0C6; border-radius: 12px; padding: 8px 8px 8px 12px; }
.composer-box:focus-within { border-color: var(--blue-2); box-shadow: 0 0 0 3px rgba(47,123,216,.15); }
.composer textarea { border: 0; padding: 4px 0; outline: none !important; max-height: 220px; min-height: 26px; resize: none; }
.composer .meta { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; gap: 10px; }
.empty-chat { margin: auto; max-width: 520px; text-align: center; padding: 30px 10px; }
.empty-chat h2 { font-size: 22px; margin: 0 0 8px; letter-spacing: -.01em; }
.suggestions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; text-align: left; }
.suggestion { border: 1px solid var(--line); background: #FBFAF7; border-radius: 9px; padding: 10px 14px; cursor: pointer; font-size: 14px; text-align: left; }
.suggestion:hover { border-color: var(--blue); background: #fff; }
.preview-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #E9E6DF; }
.preview-bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); }
.preview-bar select { width: auto; flex: 1; min-width: 0; padding: 6px 9px; }
.preview-frame { flex: 1; border: 0; width: 100%; background: #fff; }

/* ---------- lists & tables ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid #EEEAE2; }
.list-item:last-child { border-bottom: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.badge { font-size: 11.5px; font-family: var(--mono); letter-spacing: .04em; padding: 2px 7px; border-radius: 5px; background: #EEF2F7; color: var(--muted); text-transform: uppercase; }
.badge.news { background: #E6EFFA; color: var(--blue); }
.badge.knowledge { background: #EFE8FA; color: #5B3A9B; }
.badge.draft { background: #FFF4E0; color: #8A5A00; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { border: 0; background: transparent; padding: 9px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ---------- page editor ---------- */
.editor-layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; height: calc(100vh - 60px - 48px - 60px); min-height: 420px; }
.editor-frame { width: 100%; height: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.source-editor { width: 100%; height: calc(100vh - 260px); min-height: 380px; font-family: var(--mono); font-size: 13px; line-height: 1.5; white-space: pre; tab-size: 2; }
.pending-edit { font-size: 13px; border-bottom: 1px solid #EEEAE2; padding: 8px 0; }
.pending-edit del { color: var(--red); }
.pending-edit ins { color: var(--green); text-decoration: none; }

/* ---------- media ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.media-card { background: #fff; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; font-size: 12.5px; }
.media-card .thumb { aspect-ratio: 4/3; background: #F1EEE8 center/cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.media-card .info { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.media-card .info code { word-break: break-all; }
.dropzone { border: 2px dashed #CFC8BB; border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); background: #FBFAF7; }
.dropzone.over { border-color: var(--blue); background: #F0F5FB; }

/* ---------- dialogs & toasts ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; max-width: min(920px, calc(100vw - 32px)); width: 100%; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(8,26,48,.45); }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 16px; flex: 1; }
.dialog-body { padding: 18px 20px; max-height: 70vh; overflow: auto; }
.diff { font-family: var(--mono); font-size: 12px; line-height: 1.45; white-space: pre-wrap; word-break: break-all; margin: 0; }
.diff .add { background: #E6F6EC; color: #145A32; display: block; }
.diff .del { background: #FCEBEA; color: #922B21; display: block; }
.diff .hunk { color: var(--blue); display: block; margin-top: 8px; }
.diff .file { font-weight: 700; display: block; margin-top: 14px; color: var(--text); }
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 14px; max-width: 420px; white-space: pre-wrap; }
.toast.error { background: #8E2A20; }
.toast.ok { background: #17663B; }
.qr { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; width: 232px; }

@media (max-width: 1100px) {
  .chat-layout, .chat-layout.no-preview { grid-template-columns: 0 1fr 0; }
  .conv-list, .preview-col { display: none; }
  .editor-layout { grid-template-columns: 1fr; height: auto; }
  .editor-frame { height: 70vh; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .sidebar { flex-direction: row; overflow-x: auto; padding: 8px; gap: 2px; }
  .sidebar .brand, .sidebar .spacer, .sidebar .who { display: none; }
  .nav-btn { width: auto; padding: 8px 10px; font-size: 13px; }
  .nav-btn .label { display: none; }
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .view-pad { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .chat-layout { height: calc(100vh - 120px); }
}
