:root {
  --navy: #13315C; --blue: #2850A8; --gold: #C69B3A; --white: #fff;
  --bg: #fff; --soft: #F5F7FB; --line: #E3E8F0; --text: #1B2433; --muted: #5E6B80;
  --ok: #1E7F4F; --warn: #B7791F; --bad: #B42318;
  --radius: 10px; --side: 248px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--text); background: var(--bg); font-size: 15px; line-height: 1.5; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Layout */
.shell { display: flex; height: 100vh; }
.side { width: var(--side); background: var(--navy); color: #fff; display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 12px; font-weight: 700; font-size: 17px; }
.brand img { width: 30px; height: 30px; }
.brand span b { color: var(--gold); }
.nav-group { padding: 6px 10px 10px; }
.nav-title { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #9FB3D6; padding: 10px 10px 4px; }
.nav a { display: flex; justify-content: space-between; align-items: center; color: #E8EEF8; padding: 8px 10px; border-radius: 8px; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: var(--blue); color: #fff; }
.badge { background: var(--gold); color: var(--navy); font-size: 11px; font-weight: 700; border-radius: 10px; padding: 0 7px; }
.side-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.side-foot button { background: none; border: 0; color: #C9D6EE; cursor: pointer; padding: 0; }
.main { flex: 1; overflow-y: auto; min-width: 0; }
.page { max-width: 1100px; margin: 0 auto; padding: 24px 28px 60px; }
.topbar { display: none; }
h1 { font-size: 24px; margin: 0 0 4px; color: var(--navy); }
h2 { font-size: 18px; margin: 24px 0 10px; color: var(--navy); }
h3 { font-size: 15px; margin: 0 0 6px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* Components */
.btn { background: var(--blue); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.danger { background: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.stat { font-size: 26px; font-weight: 700; color: var(--navy); }
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); background: #fff; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--soft); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--soft); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill.todo { color: var(--navy); }
.pill.in_progress { background: #E8EEFB; color: var(--blue); border-color: #C9D6F3; }
.pill.submitted { background: #FBF3E3; color: #8A6417; border-color: #EBD7AE; }
.pill.revision_requested { background: #FDECEA; color: var(--bad); border-color: #F4C7C2; }
.pill.approved { background: #E6F4EC; color: var(--ok); border-color: #BFE3CF; }
.pill.urgent, .pill.high { background: #FDECEA; color: var(--bad); border-color: #F4C7C2; }
.notice { background: #FBF3E3; border: 1px solid #EBD7AE; color: #6B4E12; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
.notice.info { background: #E8EEFB; border-color: #C9D6F3; color: var(--navy); }
.empty { color: var(--muted); padding: 22px; text-align: center; }
label { display: block; font-weight: 600; font-size: 13px; margin: 10px 0 4px; color: var(--navy); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: #fff; color: var(--text);
}
textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--navy); border-color: var(--gold); font-weight: 600; text-decoration: none; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy), var(--blue)); padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { display: flex; align-items: center; gap: 10px; }

/* Chat */
.chat { display: flex; height: 100vh; }
.chat-list { width: 270px; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--soft); flex-shrink: 0; }
.chat-list .tools { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.chat-list .items { overflow-y: auto; flex: 1; padding: 6px; }
.chat-list .items a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-list .items a.active { background: #fff; border: 1px solid var(--line); font-weight: 600; }
.chat-list .items a:hover { background: #fff; text-decoration: none; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 12px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-head h1 { font-size: 17px; margin: 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px; }
.msg { max-width: 760px; margin: 0 auto 18px; }
.msg .who { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.msg .body { padding: 12px 14px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .body { background: #E8EEFB; }
.msg.assistant .body { background: #fff; border: 1px solid var(--line); }
.msg .body code { background: var(--soft); padding: 1px 4px; border-radius: 4px; }
.composer { border-top: 1px solid var(--line); padding: 14px 20px; }
.composer form { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 48px; max-height: 240px; }
.attach { cursor: pointer; }
.attach input { display: none; }
.files { max-width: 760px; margin: 0 auto 8px; display: flex; gap: 6px; flex-wrap: wrap; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50; max-width: 90vw; }
.toast.error { background: var(--bad); }

/* Mobile */
@media (max-width: 820px) {
  .shell { flex-direction: column; height: auto; min-height: 100vh; }
  .side { width: 100%; position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; width: 80vw; max-width: 300px; }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .page { padding: 16px; }
  .chat { height: calc(100vh - 52px); }
  .chat-list { display: none; }
  .chat-list.show { display: flex; position: fixed; inset: 52px 0 0 0; z-index: 20; width: 100%; }
}

.rate { margin-top: 6px; display: flex; gap: 4px; }
.rate-btn { background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer; padding: 2px 6px; opacity: .55; }
.rate-btn:hover, .rate-btn.on { opacity: 1; border-color: #C69B3A; }
