:root {
  color-scheme: dark;
  --bg: #0c1116; --sidebar: #141b22; --surface: #151c23; --surface-2: #1b242e; --surface-3: #202b37;
  --line: #2b3743; --line-soft: #222d37; --text: #eef1f4; --muted: #909baa; --orange: #ff8a00;
  --orange-soft: rgba(255, 138, 0, .14); --green: #43cf71; --green-soft: rgba(67, 207, 113, .13);
  --red: #ff6b6b; --yellow: #f0b44d; --shadow: 0 22px 60px rgba(0, 0, 0, .38);
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; overflow: hidden; background: var(--bg); color: var(--text); font: 400 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.wide { width: 100%; }
.mobile-only { display: none; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 25%, #202a34 0, var(--bg) 52%); }
.login-card { width: min(410px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: rgba(20, 27, 34, .96); box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 6px; font-size: 25px; font-weight: 500; }
.login-card > .muted { margin: 0 0 24px; }
.login-mark { width: 48px; height: 48px; display: grid; place-items: center; margin-bottom: 20px; border-radius: 13px; background: var(--orange); color: #111; font-size: 25px; }
.login-hint { margin: 16px 0 0; color: var(--muted); font-size: 11px; text-align: center; }
.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: 12px; }

.form-stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 8px; outline: 0; background: #0e141a; color: var(--text); padding: 10px 11px; transition: border-color .15s, box-shadow .15s; }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255, 138, 0, .12); }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--orange); }
.check-label { display: flex; align-items: center; gap: 9px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-note { margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 11px; }

.button, .icon-button, .tab, .agent-button, .sidebar-action { border: 0; cursor: pointer; transition: background .15s, border-color .15s, color .15s, transform .08s; }
.button { min-height: 36px; padding: 8px 14px; border-radius: 8px; font-weight: 500; }
.button:active, .icon-button:active { transform: translateY(1px); }
.button.primary { background: var(--orange); color: #14100b; }
.button.primary:hover { background: #ff9b26; }
.button.secondary { border: 1px solid var(--line); background: transparent; color: var(--text); }
.button.secondary:hover { border-color: #4a5b6d; background: var(--surface-2); }
.button.danger { border: 1px solid rgba(255, 107, 107, .45); background: rgba(255, 107, 107, .08); color: var(--red); }
.button.small { min-height: 30px; padding: 5px 10px; font-size: 12px; }
.button:disabled { opacity: .55; cursor: wait; }
.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: transparent; font-size: 18px; }
.icon-button:hover { background: var(--surface-2); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 310px minmax(0, 1fr); }
.agent-sidebar { height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--sidebar); }
.sidebar-head { height: 78px; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
.sidebar-head strong { font-size: 14px; font-weight: 500; }
.agent-list { flex: 1; overflow-y: auto; padding: 4px 10px 18px; }
.agent-button { width: 100%; display: grid; grid-template-columns: 46px minmax(0, 1fr); align-items: center; gap: 10px; margin: 3px 0; padding: 11px 12px; border-radius: 10px; background: transparent; text-align: left; }
.agent-button:hover { background: var(--surface-2); }
.agent-button.active { background: var(--orange-soft); }
.agent-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; background: var(--surface-3); color: var(--muted); font-size: 17px; }
.agent-button.active .agent-icon { background: var(--orange); color: #15100a; }
.agent-name { display: block; overflow: hidden; color: var(--text); font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.agent-state { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: var(--muted); font-size: 11px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.status-dot.ready { background: var(--green); }
.status-dot.error { background: var(--red); }
.status-dot.working { background: var(--orange); }
.sidebar-footer { padding: 12px 10px 18px; border-top: 1px solid var(--line-soft); }
.sidebar-action { width: 100%; display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 8px; background: transparent; color: var(--muted); text-align: left; }
.sidebar-action:hover { background: var(--surface-2); color: var(--text); }

.workspace { min-width: 0; height: 100vh; display: grid; grid-template-rows: 95px 56px minmax(0, 1fr); }
.workspace-head { display: flex; align-items: center; gap: 14px; padding: 18px 32px; border-bottom: 1px solid var(--line); background: #121920; }
.agent-heading { min-width: 0; flex: 1; display: flex; align-items: center; gap: 14px; }
.heading-icon { width: 54px; height: 54px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 13px; background: var(--orange); color: #171109; font-size: 23px; }
.agent-heading h1 { margin: 0; overflow: hidden; font-size: 20px; font-weight: 500; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.agent-heading p { margin: 4px 0 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.workspace-actions { display: flex; align-items: center; gap: 9px; }
.soft-badge { padding: 6px 9px; border-radius: 7px; background: var(--surface-3); color: var(--muted); font-size: 11px; }
.tabs { display: flex; align-items: stretch; gap: 2px; padding: 0 28px; overflow-x: auto; border-bottom: 1px solid var(--line); background: #121920; }
.tab { position: relative; min-width: max-content; padding: 0 14px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 400; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--orange); }
.tab.active::after { content: ""; position: absolute; right: 12px; bottom: 0; left: 12px; height: 3px; border-radius: 3px 3px 0 0; background: var(--orange); }
.count { display: inline-grid; min-width: 18px; height: 18px; place-items: center; margin-left: 5px; padding: 0 5px; border-radius: 9px; background: var(--surface-3); font-size: 10px; }
.content { min-width: 0; overflow: auto; padding: 26px 32px 36px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 16px; font-weight: 500; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.head-actions { display: flex; gap: 8px; }
.panel { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.empty-state { display: grid; place-items: center; min-height: 360px; padding: 30px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); text-align: center; }
.empty-state h2 { margin: 0 0 6px; color: var(--text); font-size: 16px; font-weight: 500; }
.empty-state p { max-width: 520px; margin: 0 0 18px; }
.loading { min-height: 260px; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--orange); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.chat-layout { height: calc(100vh - 220px); min-height: 470px; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.chat-messages { overflow-y: auto; padding: 20px; }
.chat-message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; max-width: 860px; margin: 0 0 18px; }
.chat-message.user { margin-left: auto; grid-template-columns: minmax(0, 1fr) 34px; }
.chat-message.user .message-avatar { grid-column: 2; }
.chat-message.user .message-body { grid-column: 1; grid-row: 1; background: var(--orange-soft); }
.message-avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: var(--surface-3); color: var(--orange); }
.message-body { padding: 11px 13px; border: 1px solid var(--line-soft); border-radius: 10px; background: #10171d; }
.message-body pre { margin: 0; color: var(--text); font: inherit; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-meta { margin-top: 6px; color: var(--muted); font-size: 10px; }
.message-body.failed { border-color: rgba(255, 107, 107, .4); color: var(--red); }
.chat-compose { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; padding: 14px; border-top: 1px solid var(--line); background: #11181e; }
.chat-compose textarea { min-height: 44px; max-height: 150px; resize: none; }

.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.chart-card { min-height: 285px; padding: 17px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.chart-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; margin-bottom: 24px; }
.chart-head strong { font-weight: 500; }
.chart-head small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.bar-chart { height: 190px; display: flex; align-items: end; gap: 7px; padding-top: 10px; border-bottom: 1px solid var(--line); }
.bar-column { min-width: 0; flex: 1; display: grid; align-items: end; justify-items: center; gap: 7px; height: 100%; }
.bar { width: 70%; min-height: 2px; border-radius: 5px 5px 0 0; background: linear-gradient(180deg, #ff9d2e, var(--orange)); }
.bar-column small { color: var(--muted); font-size: 9px; }
.status-chart { display: grid; gap: 16px; }
.status-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 40px; align-items: center; gap: 10px; }
.status-row span { color: var(--muted); font-size: 11px; }
.status-track { height: 8px; overflow: hidden; border-radius: 4px; background: var(--surface-3); }
.status-fill { height: 100%; border-radius: inherit; background: var(--orange); }
.chart-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.summary-item { padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.summary-item strong { display: block; font-size: 20px; font-weight: 500; }
.summary-item span { color: var(--muted); font-size: 10px; }
.dashboard-toolbar { display: flex; align-items: center; gap: 8px; }
.period-switch { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.period-switch button { min-height: 28px; padding: 4px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; }
.period-switch button.active { background: var(--orange-soft); color: var(--orange); }
.dashboard-widget { cursor: grab; }
.dashboard-widget.dragging { opacity: .45; }
.widget-actions { display: flex; align-items: center; gap: 6px; }
.widget-actions .icon-button { width: 30px; height: 30px; font-size: 15px; }
.soft-badge.error { background: rgba(255, 107, 107, .12); color: var(--red); }
.source-warning { margin-bottom: 14px; padding: 10px 12px; border: 1px solid rgba(240, 180, 77, .38); border-radius: 8px; background: rgba(240, 180, 77, .08); color: var(--yellow); font-size: 11px; }
.dashboard-sync-state { margin: -8px 0 12px; color: var(--muted); font-size: 10px; }
.line-chart { height: 195px; }
.line-chart svg { width: 100%; height: 166px; overflow: visible; }
.chart-axis { stroke: var(--line); stroke-width: .5; vector-effect: non-scaling-stroke; }
.chart-line { fill: none; stroke: var(--orange); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-line.comparison { stroke: #708295; stroke-dasharray: 5 4; }
.chart-point { fill: var(--orange); stroke: var(--surface); stroke-width: 1; vector-effect: non-scaling-stroke; cursor: help; }
.chart-labels { display: flex; justify-content: space-between; gap: 3px; color: var(--muted); }
.chart-labels small { overflow: hidden; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.chart-empty { height: 190px; display: grid; place-content: center; gap: 5px; padding: 18px; border: 1px dashed var(--line); border-radius: 9px; color: var(--muted); text-align: center; }
.chart-empty strong { color: var(--text); font-weight: 500; }
.chart-empty span { max-width: 400px; font-size: 11px; }
.lazy-chart { min-height: 195px; }
.chart-loading { height: 195px; display: grid; place-items: center; border: 1px dashed var(--line-soft); border-radius: 9px; color: var(--muted); font-size: 10px; }
.chart-legend { display: flex; align-items: center; gap: 6px; margin-top: 7px; color: var(--muted); font-size: 9px; }
.chart-legend i { width: 16px; height: 2px; background: var(--orange); }
.chart-legend i.comparison { background: #708295; }
.metric-bars { height: 195px; }
.section-title { margin: 24px 0 10px; color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .06em; }

.list-row { display: grid; grid-template-columns: minmax(220px, 1fr) 145px minmax(170px, 250px) 150px; align-items: center; gap: 14px; width: 100%; padding: 15px 17px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
.row-title strong { display: block; font-weight: 500; }
.row-title small { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.progress-copy { color: var(--muted); font-size: 11px; }
.progress-track { height: 5px; margin-top: 7px; overflow: hidden; border-radius: 4px; background: var(--surface-3); }
.progress-fill { height: 100%; border-radius: inherit; background: var(--orange); }
.tag { display: inline-flex; align-items: center; width: fit-content; min-height: 25px; padding: 3px 8px; border-radius: 6px; background: var(--surface-3); color: var(--muted); font-size: 10px; }
.tag.approval { background: rgba(240, 180, 77, .13); color: var(--yellow); }
.tag.success { background: var(--green-soft); color: var(--green); }

.calendar-toolbar { display: flex; align-items: center; gap: 8px; }
.calendar-toolbar strong { min-width: 150px; text-align: center; font-size: 14px; font-weight: 500; }
.calendar-scroll { overflow-x: auto; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(95px, 1fr)); min-width: 700px; }
.weekday { padding: 9px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; text-align: center; }
.calendar-day { min-height: 112px; padding: 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.calendar-day.muted-day { opacity: .35; }
.day-number { color: var(--muted); font-size: 11px; }
.calendar-event { display: block; width: 100%; margin-top: 6px; padding: 5px 6px; border: 0; border-radius: 5px; overflow: hidden; background: var(--orange-soft); color: var(--orange); font-size: 10px; text-align: left; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }

.journal-row { display: grid; grid-template-columns: 140px 30px minmax(0, 1fr) 120px; align-items: start; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.journal-row:last-child { border-bottom: 0; }
.journal-time, .journal-type { color: var(--muted); font-size: 11px; }
.journal-icon { color: var(--orange); }
.journal-copy strong { display: block; font-weight: 500; }
.journal-copy small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }

.integration-grid { display: grid; grid-template-columns: repeat(2, minmax(250px, 1fr)); gap: 12px; }
.integration-card { padding: 17px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.integration-card.active { border-color: rgba(67, 207, 113, .45); }
.integration-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.integration-head strong { font-weight: 500; }
.integration-card p { min-height: 38px; margin: 8px 0 15px; color: var(--muted); font-size: 11px; }
.integration-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.provider-list { display: grid; gap: 10px; }
.provider-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 11px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.provider-logo { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 9px; background: var(--surface-3); color: var(--orange); }
.provider-row strong { display: block; font-weight: 500; }
.provider-row small { color: var(--muted); font-size: 10px; }
.provider-actions { display: flex; gap: 6px; }

.data-layout { min-height: 520px; display: grid; grid-template-columns: 210px 330px minmax(0, 1fr); overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.data-column { min-width: 0; border-right: 1px solid var(--line); }
.data-column:last-child { border-right: 0; }
.data-head { height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 13px; border-bottom: 1px solid var(--line); font-weight: 500; }
.folder-button, .file-button { width: 100%; padding: 11px 13px; border: 0; border-bottom: 1px solid var(--line-soft); background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.folder-button:hover, .file-button:hover, .folder-button.active, .file-button.active { background: var(--orange-soft); }
.folder-button { display: flex; justify-content: space-between; }
.file-button strong { display: block; overflow-wrap: anywhere; font-weight: 500; }
.file-button small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.document-preview { padding: 18px; }
.document-preview pre { margin: 0; font: 400 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.document-actions { display: flex; gap: 7px; }

.modal { width: min(720px, calc(100vw - 28px)); max-height: calc(100vh - 40px); padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--sidebar); color: var(--text); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(0, 0, 0, .66); backdrop-filter: blur(3px); }
.modal form { max-height: calc(100vh - 40px); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.modal-head { display: flex; align-items: start; justify-content: space-between; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 500; }
.modal-body { overflow-y: auto; padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal-error { flex: 1 1 auto; align-self: center; min-width: 0; margin-right: 8px; line-height: 1.35; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: min(420px, calc(100vw - 44px)); padding: 11px 14px; border: 1px solid rgba(67, 207, 113, .4); border-radius: 9px; opacity: 0; transform: translateY(12px); pointer-events: none; background: #17291e; color: #a9eabf; box-shadow: var(--shadow); transition: .2s; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { border-color: rgba(255, 107, 107, .4); background: #2a1719; color: #ffb1b1; }

@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 260px minmax(0, 1fr); }
  .workspace-head, .content { padding-inline: 22px; }
  .tabs { padding-inline: 18px; }
  .data-layout { grid-template-columns: 170px 270px minmax(0, 1fr); }
  .list-row { grid-template-columns: minmax(190px, 1fr) 125px minmax(150px, 210px); }
  .list-row > :last-child { display: none; }
}
@media (max-width: 736px) {
  body { overflow: auto; }
  .app-shell { display: block; }
  .agent-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: 290px; transform: translateX(-100%); box-shadow: var(--shadow); transition: transform .2s; }
  .agent-sidebar.open { transform: translateX(0); }
  .workspace { height: 100vh; grid-template-rows: auto 52px minmax(0, 1fr); }
  .mobile-only { display: inline-grid; }
  .workspace-head { min-height: 84px; padding: 13px; }
  .heading-icon { width: 42px; height: 42px; font-size: 18px; }
  .agent-heading h1 { font-size: 17px; }
  .agent-heading p, #edit-agent, #local-badge { display: none; }
  .tabs { padding: 0 7px; }
  .tab { padding: 0 10px; font-size: 12px; }
  .content { padding: 16px 12px 24px; }
  .page-head { align-items: start; }
  .charts, .integration-grid { grid-template-columns: 1fr; }
  .chart-summary { grid-template-columns: repeat(2, 1fr); }
  .list-row { grid-template-columns: minmax(0, 1fr) 110px; }
  .list-row > :nth-child(3), .list-row > :nth-child(4) { display: none; }
  .journal-row { grid-template-columns: 90px 20px minmax(0, 1fr); }
  .journal-type { display: none; }
  .data-layout { display: block; min-height: 0; }
  .data-column { border-right: 0; border-bottom: 1px solid var(--line); }
  .data-column:first-child { max-height: 190px; overflow-y: auto; }
  .data-column:nth-child(2) { max-height: 240px; overflow-y: auto; }
  .document-preview { min-height: 320px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .modal-actions { flex-wrap: wrap; }
  .modal-error { flex-basis: 100%; margin-right: 0; }
}
@media (max-width: 420px) {
  .login-card { padding: 25px 20px; }
  .workspace-actions { gap: 5px; }
  .workspace-head, .agent-heading { gap: 8px; }
  .chat-layout { height: calc(100vh - 190px); }
  .chat-compose { grid-template-columns: 1fr; }
  .head-actions { flex-wrap: wrap; justify-content: flex-end; }
}
