/* AppSite Agents */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde3ed;
  --text: #1a2332;
  --text-muted: #6b7a8f;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --radius: 8px;
  --sidebar-w: 220px;
}

html, body { width: 100%; height: 100%; min-height: 100%; overflow: hidden;   padding-bottom: 28px;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

#app, .app, .app-shell { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#appsiteTopNav, #appsite-topnav, .appsite-topnav, .appsite-topnav-shell, header.appsite-topnav, .tl-topnav, .topnav-module {
  flex: 0 0 auto; width: 100%; max-width: 100%; z-index: 1000;
}

/* Status bar */
#statusBar { font-size: 12px; padding: 4px 16px; background: var(--primary-light); color: var(--primary); border-top: 1px solid var(--border); min-height: 24px; display: block; position: fixed; bottom: 0; left: 0; right: 0; z-index: 150; }
#statusBar:empty { padding: 0; min-height: 0; border-top: none; }
#statusBar.error { background: var(--danger-light); color: var(--danger); }

/* ── Topbar ────────────────────────────────────────────────────────────────── */
header.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; flex-shrink: 0; }
header.topbar h1 { font-size: 18px; font-weight: 700; }
header.topbar .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
header.topbar input[type="search"], header.topbar select { font-size: 13px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); min-height: 32px; }
header.topbar button { font-size: 13px; padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; min-height: 32px; }
header.topbar #newPostBtn { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* ── Grid layout (list + editor) ───────────────────────────────────────────── */
.workspace { padding: 12px; display: flex; flex: 1; min-height: 0; flex-direction: column; gap: 10px; overflow: hidden; }

/* Hardcoded fallback grid (does not depend on appsite-module-layout.js running) */
.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.layout.desk-sidebar-collapsed { grid-template-columns: 44px minmax(0, 1fr); }
.order-list {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
@media (max-width: 760px) {
  .layout, .layout.desk-sidebar-collapsed { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .order-list { max-height: 260px; }
}

.order-item { padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.order-item:hover { background: var(--bg); }
.order-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.order-item:last-child { border-bottom: 0; }
#emptyPosts { text-align: center; color: var(--text-muted); padding: 32px 16px; font-size: 13px; }

.order-editor { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; }

#postEditor[hidden], #postEditorEmpty[hidden] { display: none; }

/* ── Editor header ─────────────────────────────────────────────────────────── */
.wo-header-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.wo-header-left { display: flex; align-items: center; gap: 10px; }
.wo-header-left h2 { font-size: 16px; font-weight: 700; }
.wo-status-chip { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 2px 9px; }
.wo-header-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.btn-primary-action { background: var(--primary); border: 1px solid var(--primary); color: #fff; font-weight: 600; padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; min-height: 32px; }
.btn-primary-action:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 13px; min-height: 32px; }
.btn-danger:hover { border-color: var(--danger); background: var(--danger-light); }
#editorBackBtn { font-size: 12px; font-weight: 600; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; cursor: pointer; color: var(--text-muted); }
#editorBackBtn:hover { border-color: var(--primary); color: var(--primary); }
#exportPdfBtn { font-size: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; cursor: pointer; min-height: 32px; }

/* ── Tab bar ───────────────────────────────────────────────────────────────── */
.wo-tabs { display: flex; gap: 2px; padding: 8px 20px 0; background: var(--surface); border-bottom: 2px solid var(--border); position: sticky; top: 57px; z-index: 9; flex-wrap: wrap; }
.wo-tab { padding: 7px 14px; border: 1px solid transparent; border-bottom: none; border-radius: 6px 6px 0 0; background: transparent; font: inherit; font-size: 12px; font-weight: 600; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.wo-tab:hover { background: var(--bg); color: var(--text); }
.wo-tab.active { background: var(--surface); border-color: var(--border); color: var(--primary); margin-bottom: -2px; padding-bottom: 9px; }

/* ── Form body ─────────────────────────────────────────────────────────────── */
.wo-tab-panel { display: flex; flex-direction: column; gap: 12px; padding: 16px 20px; }
.wo-form { display: flex; flex-direction: column; }
.wo-row { display: flex; gap: 12px; align-items: flex-start; }
.wo-row.four-col { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.wo-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.wo-form input, .wo-form select, .wo-form textarea { font-size: 13px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-family: inherit; width: 100%; }
.wo-form textarea { resize: vertical; }

/* ── Legacy app-layout (kept for non-desk standalone) ─────────────────────── */
.app-layout { display: flex; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 8px; border-bottom: 1px solid var(--border); }
.sidebar-title { font-size: 13px; font-weight: 700; color: var(--text); }
.sidebar-section-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); padding: 8px 12px 2px; }
.sidebar-scroll { flex: 1 1 auto; overflow-y: auto; padding: 4px 0; }
.sidebar-item { display: flex; align-items: center; gap: 6px; padding: 7px 12px; font-size: 13px; cursor: pointer; border-radius: 0; color: var(--text); transition: background 0.1s; }
.sidebar-item:hover { background: var(--bg); }
.sidebar-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sidebar-empty { font-size: 12px; color: var(--text-muted); padding: 8px 12px; }

/* Agent type / status dots */
.agent-type-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--text-muted); }
.agent-type-dot.ai { background: var(--primary); }
.agent-type-dot.human { background: var(--success); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; margin-left: auto; background: var(--text-muted); }
.status-dot.active { background: var(--success); }
.status-dot.away { background: var(--warn); }

/* Workspace */
.workspace { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.workspace-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.workspace-header-group { display: flex; flex-direction: column; margin-right: auto; }
.workspace-title { font-size: 15px; font-weight: 700; color: var(--text); }
.workspace-subtitle { font-size: 11px; color: var(--text-muted); }
.workspace-scroll { flex: 1 1 auto; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

/* Summary grid */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.summary-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.summary-value { font-size: 22px; font-weight: 700; color: var(--text); }
.summary-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 13px; font-weight: 700; }
.card-body { padding: 0; overflow-x: auto; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 8px 12px; text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }
.muted { color: var(--text-muted); }

/* Badges */
.badge { display: inline-flex; align-items: center; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.badge-ai { background: var(--primary-light); color: var(--primary); border-color: transparent; }
.badge-human { background: #f0fdf4; color: #16a34a; border-color: transparent; }
.badge-active { background: #f0fdf4; color: #16a34a; border-color: transparent; }

.status-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--bg); color: var(--text-muted); }
.status-chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.7; }
.status-chip.active { background: #f0fdf4; color: #16a34a; }
.status-chip.away { background: #fffbeb; color: #d97706; }
.status-chip.inactive { background: var(--bg); color: var(--text-muted); }

/* Empty state */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state h3 { font-size: 15px; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; padding: 6px 14px; border-radius: 6px; border: 1px solid transparent; cursor: pointer; transition: background 0.15s, color 0.15s; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-surface { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-surface:hover { background: var(--bg); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { font-size: 12px; padding: 4px 10px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.field-input { font-size: 13px; font-family: inherit; border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; color: var(--text); background: var(--surface); outline: none; width: 100%; }
.field-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
textarea.field-input { resize: vertical; min-height: 60px; }
.form-grid { display: grid; gap: 10px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--surface); border-radius: 10px; box-shadow: 0 8px 40px rgba(0,0,0,0.18); width: 100%; max-width: 480px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-wide { max-width: 600px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1; padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { flex: 1 1 auto; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }

/* Post modal — tabbed layout */
.post-modal-wide { max-width: 760px; height: 88vh; }
.post-tabs { display: flex; gap: 2px; padding: 8px 16px 0; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.post-tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer; margin-bottom: -1px; border-radius: 6px 6px 0 0; transition: color 0.12s, border-color 0.12s; }
.post-tab:hover { color: var(--text); }
.post-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.post-modal-body { flex: 1 1 auto; min-height: 0; display: flex; overflow: hidden; }
.post-tab-panel { display: none; flex: 1 1 auto; overflow-y: auto; padding: 16px; flex-direction: column; gap: 12px; }
.post-tab-panel.active { display: flex; }
.post-preview-panel { padding: 12px; background: var(--bg); }

/* Landing page */
.landing-wrap { max-width: 880px; margin: 0 auto; padding: 60px 24px 40px; }
.landing-hero { text-align: center; margin-bottom: 48px; }
.eyebrow { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--primary); margin-bottom: 8px; }
.landing-hero h1 { font-size: 42px; font-weight: 800; color: var(--text); margin-bottom: 14px; }
.landing-sub { font-size: 16px; color: var(--text-muted); max-width: 540px; margin: 0 auto 28px; }
.landing-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn-signin { display: inline-flex; align-items: center; background: var(--primary); color: #fff; padding: 10px 24px; border-radius: 8px; font-weight: 700; font-size: 14px; text-decoration: none; }
.btn-signin:hover { background: var(--primary-hover); }
.btn-hub { display: inline-flex; align-items: center; background: var(--surface); color: var(--text); padding: 10px 24px; border-radius: 8px; font-weight: 600; font-size: 14px; text-decoration: none; border: 1px solid var(--border); }
.btn-hub:hover { background: var(--bg); }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.feature-card svg { width: 24px; height: 24px; stroke: var(--primary); fill: none; stroke-width: 1.5; margin-bottom: 10px; }
.feature-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.feature-card p { font-size: 13px; color: var(--text-muted); }
.landing-footer { text-align: center; padding: 24px; font-size: 12px; }
.landing-footer a { color: var(--text-muted); }

/* SSO banner */
.sso-banner { display: flex; align-items: center; gap: 10px; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 16px; font-size: 13px; }
.sso-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.sso-name { font-weight: 600; }
.sso-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.btn-link { color: var(--primary); font-size: 13px; font-weight: 600; text-decoration: none; }
.btn-sm { font-size: 12px; padding: 4px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; cursor: pointer; }
