:root {
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --page: #f6f8fb;
  --panel: #ffffff;
  --nav: #071a2f;
  --gold: #d6a531;
  --green: #079455;
  --blue: #2563eb;
  --red: #d92d20;
  --orange: #f97316;
  --purple: #7c3aed;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  min-height: 100vh;
}
body.auth-screen .sidebar,
body.auth-screen .shell {
  display: none;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.login-view {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(7, 26, 47, .96), rgba(14, 32, 56, .94)),
    radial-gradient(circle at 50% 0%, rgba(214, 165, 49, .18), transparent 36%),
    #071a2f;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
  overflow: auto;
}
.login-card {
  width: min(560px, 100%);
  background: rgba(13, 31, 55, .88);
  border: 1px solid rgba(244, 210, 122, .18);
  border-radius: 20px;
  padding: 36px;
  display: grid;
  gap: 18px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .32);
  color: #f8fbff;
  backdrop-filter: blur(16px);
}
.login-brand {
  color: var(--gold);
  margin-bottom: 4px;
}
.login-card h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.2;
  text-align: center;
  color: #ffffff;
}
.login-card h1::before {
  content: "بوابة نظام واتساب استصناع";
}
.login-card h1 {
  font-size: 0;
}
.login-card h1::before {
  font-size: 34px;
}
.login-card p {
  margin: -4px auto 8px;
  max-width: 420px;
  text-align: center;
  color: #aebbd0;
  font-size: 17px;
  line-height: 1.8;
}
.login-card p::before {
  content: "سجلي الدخول لإدارة محادثات واتساب، الأقسام، والردود من مكان واحد";
}
.login-card p {
  font-size: 0;
}
.login-card p::before {
  font-size: 17px;
}
.login-card::after {
  content: "مدير النظام  |  الموظفون";
  order: 2;
  min-height: 54px;
  border: 1px solid rgba(244, 210, 122, .2);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #f4d27a;
  background: rgba(255, 255, 255, .05);
  font-weight: 700;
}
.login-card label {
  order: 3;
  display: grid;
  gap: 9px;
  color: #c8d3e5;
  font-weight: 600;
}
.login-card input {
  border: 1px solid rgba(195, 210, 232, .22);
  border-radius: 14px;
  min-height: 56px;
  padding: 0 16px;
  background: rgba(7, 26, 47, .68);
  color: #ffffff;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.login-card input:focus {
  border-color: rgba(244, 210, 122, .72);
  box-shadow: 0 0 0 4px rgba(214, 165, 49, .12);
  background: rgba(7, 26, 47, .86);
}
.login-card button {
  order: 4;
  border: 0;
  border-radius: 16px;
  min-height: 58px;
  background: linear-gradient(135deg, #d6a531, #f4d27a);
  color: #071a2f;
  font-weight: 800;
  box-shadow: 0 18px 34px rgba(214, 165, 49, .22);
  transition: transform .18s ease, box-shadow .18s ease;
}
.login-card button:hover {
  transform: translateY(-1px);
  box-shadow: 0 22px 38px rgba(214, 165, 49, .28);
}
.login-card small {
  order: 6;
  display: none;
  color: #8f9db2;
  text-align: center;
}
.login-error {
  order: 5;
  min-height: 20px;
  color: #ffb4ab;
  text-align: center;
  font-weight: 700;
}

.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: 260px;
  background: var(--nav);
  color: white;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--gold); }
.brand-mark {
  width: 42px;
  height: 42px;
  border: 2px solid var(--gold);
  display: grid;
  place-items: center;
  font-size: 24px;
}
.brand strong { display: block; font-size: 28px; line-height: 1; }
.brand span { display: block; font-size: 10px; letter-spacing: 3px; color: #f4d27a; margin-top: 5px; }
.brand {
  justify-content: center;
}
.brand::before {
  content: "";
  display: block;
  width: min(210px, 100%);
  height: 90px;
  background: url("/estesnaa-logo.png") center / contain no-repeat;
}
.login-brand::before {
  width: min(260px, 100%);
  height: 112px;
  margin-inline: auto;
}
.brand-mark,
.brand strong,
.brand span {
  display: none;
}
.nav { display: grid; gap: 8px; }
.nav-item {
  border: 1px solid transparent;
  background: transparent;
  color: #e6eef8;
  min-height: 48px;
  border-radius: 8px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: right;
}
.nav-item b {
  margin-inline-start: auto;
  min-width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #e11d48;
  color: white;
  font-size: 12px;
}
.nav-item.active {
  color: var(--gold);
  border-color: var(--gold);
  background: rgba(214, 165, 49, .08);
}
.quick {
  border-top: 1px solid rgba(255,255,255,.12);
  padding-top: 16px;
  display: grid;
  gap: 10px;
}
.quick span { color: #9fb1c8; font-size: 13px; }
.quick button, .logout {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  background: rgba(255,255,255,.07);
  color: white;
  text-align: right;
  padding: 0 14px;
}
.logout { margin-top: auto; background: transparent; color: #e6eef8; }

.shell { margin-inline-start: 260px; min-height: 100vh; }
.topbar {
  height: 76px;
  background: white;
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.search {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  width: min(420px, 45vw);
  background: white;
}
.search input { border: 0; outline: 0; padding: 12px 14px; flex: 1; }
.search button { border: 0; background: white; width: 48px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 14px; }
.icon-btn {
  position: relative;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  width: 44px;
  height: 44px;
}
.icon-btn b {
  position: absolute;
  top: -7px;
  inset-inline-end: -7px;
  background: #e11d48;
  color: white;
  border-radius: 999px;
  min-width: 22px;
  height: 22px;
  font-size: 12px;
}
.status-pill {
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  color: #067647;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.status-pill.mock { border-color: #fed7aa; background: #fff7ed; color: #c2410c; }
.preview-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #fdb022;
  background: #fffaeb;
  color: #93370d;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 700;
}
.preview-banner button {
  border: 0;
  background: #93370d;
  color: white;
  border-radius: 6px;
  padding: 5px 8px;
}
.profile { display: flex; align-items: center; gap: 10px; }
.profile span { display: block; color: var(--muted); font-size: 12px; }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #eef4ff;
  color: #1849a9;
  font-weight: 700;
}

.view { display: none; padding: 28px; }
.active-view { display: block; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 22px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 25px; }
h2 { font-size: 18px; }
p { color: var(--muted); margin-top: 6px; }
.daily-counters {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  width: min(820px, 100%);
}
.metric-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  display: grid;
  gap: 7px;
  min-height: 74px;
  box-shadow: 0 8px 22px rgba(16, 24, 40, .05);
}
.metric-card small {
  color: var(--muted);
  font-size: 12px;
}
.metric-card b {
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}
.metric-unread { border-top: 3px solid #2563eb; }
.metric-admin { border-top: 3px solid #e11d48; }
.metric-inventors { border-top: 3px solid #079455; }
.metric-factories { border-top: 3px solid #d6a531; }
.metric-activity { border-top: 3px solid #667085; }
.metric-activity b { font-size: 18px; }

.department-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.dept-card {
  background: white;
  border: 1px solid var(--line);
  border-top: 3px solid var(--dept);
  border-radius: 8px;
  min-height: 126px;
  padding: 16px;
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 8px 12px;
  align-content: start;
  text-align: start;
}
.dept-icon {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--dept) 12%, white);
  color: var(--dept);
  grid-row: span 3;
  font-size: 22px;
}
.dept-card b { align-self: end; }
.dept-card small { color: var(--muted); }
.dept-card small:last-child { font-size: 12px; }

.dashboard-grid, .control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(360px, .95fr);
  gap: 18px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  min-width: 0;
  box-shadow: 0 8px 22px rgba(16, 24, 40, .04);
}
.panel.wide { grid-column: span 1; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-head button, .chat-actions button, .composer button, .admin-alert button, dialog button {
  border: 1px solid var(--line);
  background: white;
  color: #175cd3;
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
}

.table { display: grid; gap: 0; }
.row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto auto;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid #f0f2f5;
  padding: 14px 0;
}
.row:last-child { border-bottom: 0; }
.row > div b { font-size: 15px; }
.row > div small {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.7;
}
.row small, .muted { color: var(--muted); }
.tag {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  color: #344054;
  background: #f2f4f7;
  white-space: nowrap;
}
.performance-list { display: grid; gap: 12px; }
.perf {
  display: grid;
  grid-template-columns: 1fr repeat(3, 44px);
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid #f0f2f5;
}
.perf b { color: var(--green); text-align: center; }
.perf div b {
  display: inline-block;
  text-align: start;
  color: var(--green);
}
.performance-list::before {
  content: "الموظف        الردود   الجديد   الإجمالي";
  color: var(--muted);
  font-size: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f0f2f5;
  white-space: pre;
}

.admin-alert {
  margin-top: 18px;
  border: 1px solid #fed7aa;
  background: #fff7ed;
  border-radius: 8px;
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 8px 22px rgba(249, 115, 22, .08);
}
.admin-alert div { display: flex; align-items: center; gap: 10px; }
.admin-alert b {
  background: #e11d48;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: grid;
  place-items: center;
}

.chat-layout {
  display: grid;
  /* Default: filters + conversation list + chat panel only.
     customer-card is hidden (via .hidden) and reserves no track here. */
  grid-template-columns: 210px minmax(300px, 360px) minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
  min-width: 0;
  height: calc(100vh - 132px);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
/* If customer-card becomes visible again (JS removes .hidden), the
   layout automatically restores its own track without touching JS. */
.chat-layout:has(> .customer-card:not(.hidden)) {
  grid-template-columns: 210px minmax(300px, 360px) minmax(0, 1fr) minmax(320px, .85fr);
}
.filters, .conversation-list, .customer-card {
  border-inline-end: 1px solid var(--line);
  padding: 18px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #c7ccd4 transparent;
}
.conversation-list {
  padding: 12px;
}
.filters {
  width: 210px;
  min-width: 210px;
  max-width: 210px;
}
.filters::-webkit-scrollbar, .conversation-list::-webkit-scrollbar, .customer-card::-webkit-scrollbar {
  width: 6px;
}
.filters::-webkit-scrollbar-thumb, .conversation-list::-webkit-scrollbar-thumb, .customer-card::-webkit-scrollbar-thumb {
  background: #c7ccd4;
  border-radius: 999px;
}
.filters::-webkit-scrollbar-thumb:hover, .conversation-list::-webkit-scrollbar-thumb:hover, .customer-card::-webkit-scrollbar-thumb:hover {
  background: #a7adb8;
}
.conversation-list {
  background: #fbfcfe;
}
.conversation-list .list-head select {
  display: none;
}
.customer-card { border-inline-end: 0; border-inline-start: 1px solid var(--line); }
.filter-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #f0f2f5;
}
.filter-item-clickable {
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: inherit;
  border-radius: 6px;
}
.filter-item-clickable:hover { background: #f8fafc; }
.filter-item-clickable.active {
  background: #eff6ff;
  color: #175cd3;
  font-weight: 700;
}
.needs-admin-badge {
  display: inline-block;
  background: #fee4e2;
  color: #b42318;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-inline-start: 6px;
}
.conversation-item.needs-admin {
  border-color: #fda29b;
}
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 10px;
  background: white;
}
.conversation-item {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
  display: grid;
  gap: 8px;
  text-align: right;
  overflow-wrap: break-word;
  word-break: normal;
}
.conversation-item.active {
  background: #f8fbff;
  border-color: #c7d7fe;
}
.conversation-top { display: flex; justify-content: space-between; gap: 8px; }
.conversation-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  min-width: 0;
  min-height: calc(100% - 52px);
}
.conversation-column {
  border: 1px solid var(--line);
  border-top: 3px solid var(--dept);
  border-radius: 8px;
  background: white;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.conversation-column header {
  min-height: 70px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.conversation-column.department-inventors header { background: #F2FBF6; }
.conversation-column.department-factories header { background: #F3F8FF; }
.conversation-column.department-events header { background: #F8F5FF; }
.conversation-column.department-quality header { background: #F2FCFC; }
.conversation-column.department-support header { background: #FFF8F1; }
.conversation-column h3 {
  margin: 0;
  font-size: 16px;
}
.conversation-column header span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}
.conversation-column header b {
  min-width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--dept);
  color: white;
  display: grid;
  place-items: center;
  font-size: 12px;
}
.conversation-column-items {
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
}

/* ==== Admin-only layout adjustments ====
   يُضاف كلاس is-admin-view على <body> فقط لمن يملك صلاحية settings.permissions
   (انظر showApp() في app.js). لا يؤثر إطلاقًا على صفحة الموظفين. */
.is-admin-view .chat-layout {
  grid-template-columns: 200px minmax(650px, 760px) minmax(380px, 1fr);
  gap: 12px;
}
.is-admin-view .conversation-list {
  min-width: 650px;
  max-width: 760px;
}
.is-admin-view .filters {
  width: 200px;
  min-width: 200px;
  max-width: 200px;
}
.is-admin-view .conversation-board {
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 10px;
}
.is-admin-view .conversation-column {
  max-height: 420px;
}
.is-admin-view .conversation-column-items {
  padding: 6px;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.is-admin-view .conversation-item {
  padding: 10px;
  gap: 6px;
}
@media (max-width: 1400px) {
  .is-admin-view .chat-layout {
    grid-template-columns: 190px minmax(620px, 720px) minmax(340px, 1fr);
  }
  .is-admin-view .conversation-list {
    min-width: 620px;
    max-width: 720px;
  }
  .is-admin-view .filters {
    width: 190px;
    min-width: 190px;
    max-width: 190px;
  }
  .is-admin-view .conversation-board {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
  }
}
/* ==== End admin-only layout adjustments ==== */
.column-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px 10px;
  text-align: center;
}
.unread {
  background: #1570ef;
  color: white;
  border-radius: 999px;
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
}
.chat-panel { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.empty-state { margin: auto; color: var(--muted); }
.hidden { display: none !important; }
.chat-content { display: flex; flex-direction: column; height: 100%; min-width: 0; }
.chat-head {
  border-bottom: 1px solid var(--line);
  min-height: 76px;
  padding: 16px 22px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}
.chat-head span { color: var(--muted); font-size: 13px; }
.chat-actions { display: flex; gap: 8px; align-items: center; }
.mobile-back-btn {
  display: none;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  width: 38px;
  height: 38px;
  font-size: 18px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 24px 26px;
  background: #f1f5f9;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #c7ccd4 transparent;
}
.messages::-webkit-scrollbar {
  width: 6px;
}
.messages::-webkit-scrollbar-thumb {
  background: #c7ccd4;
  border-radius: 999px;
}
.messages::-webkit-scrollbar-thumb:hover {
  background: #a7adb8;
}
.bubble {
  max-width: min(560px, 78%);
  border-radius: 8px;
  padding: 13px 16px;
  line-height: 1.7;
  background: white;
  border: 1px solid var(--line);
}
.new-messages-indicator {
  position: absolute;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--blue, #2563eb);
  color: white;
  border: 0;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(37, 99, 235, .3);
  cursor: pointer;
  z-index: 3;
}
.bubble.outbound { align-self: flex-start; background: #dcfce7; border-color: #bbf7d0; }
.bubble.inbound { align-self: flex-end; }
.bubble time { display: block; color: var(--muted); font-size: 11px; margin-top: 6px; }
.bubble.bot-draft {
  background: #fff7ed;
  border-color: #fed7aa;
}
.bubble.deleted {
  background: #f8fafc;
  border-style: dashed;
  color: var(--muted);
  font-style: italic;
}
.bubble-tools {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}
.msg-delete-btn {
  border: 0;
  background: transparent;
  color: #b42318;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.msg-delete-btn:hover { background: #fef2f2; }
.msg-delete-btn:disabled { opacity: .6; cursor: wait; }
.file-delete-btn {
  border: 0;
  background: transparent;
  color: #b42318;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
}
.file-delete-btn:hover { background: #fef2f2; }
.file-delete-btn:disabled { opacity: .6; cursor: wait; }
.msg-edit-btn {
  border: 0;
  background: transparent;
  color: #175cd3;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  margin-inline-end: 4px;
}
.msg-edit-btn:hover { background: #eff6ff; }
.msg-edit-btn:disabled { opacity: .6; cursor: wait; }
.msg-edited-note {
  color: var(--muted);
  font-size: 11px;
  margin-inline-start: 6px;
}
.admin-conv-menu {
  position: relative;
}
.admin-conv-menu-list {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 4px);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .12);
  display: grid;
  min-width: 160px;
  z-index: 20;
  padding: 4px;
}
.admin-conv-menu-list button {
  text-align: right;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.admin-conv-menu-list button:hover { background: #f8fafc; }
.admin-conv-menu-list button.danger-item {
  color: #b42318;
}
.admin-conv-menu-list button.danger-item:hover { background: #fef2f2; }
.admin-show-archived {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  font-size: 12.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.bot-draft-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #fed7aa;
}
.bot-draft-actions span {
  color: #9a3412;
  font-size: 12px;
  font-weight: 700;
}
.bot-draft-actions button {
  border: 0;
  border-radius: 8px;
  background: #16a34a;
  color: #fff;
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
}
.bot-draft-actions button:disabled {
  cursor: wait;
  opacity: 0.75;
}
.attachment-download {
  appearance: none;
  display: grid;
  gap: 4px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #d7e7ff;
  border-radius: 8px;
  background: #f5f9ff;
  color: #0f3f84;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
  text-align: right;
  line-height: 1.5;
}
.attachment-download strong {
  color: #102a43;
  font-size: 14px;
}
.attachment-download span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  direction: ltr;
  text-align: right;
}
.attachment-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(2, 15, 33, 0.58);
}
.attachment-preview-modal.open { display: flex; }
.attachment-preview-panel {
  width: min(980px, 94vw);
  height: min(760px, 88vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
}
.attachment-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.attachment-preview-close {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 8px 14px;
  cursor: pointer;
}
.attachment-preview-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  background: #f8fafc;
  display: grid;
  place-items: center;
}
.attachment-preview-media {
  display: block;
  max-width: 100%;
  max-height: calc(88vh - 96px);
  object-fit: contain;
  margin: 0 auto;
  border-radius: 8px;
}
.attachment-preview-frame {
  width: 100%;
  height: 72vh;
  border: 0;
  border-radius: 8px;
  background: white;
}
.attachment-preview-audio {
  width: 100%;
}
.attachment-preview-loading {
  display: grid;
  min-height: 220px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}
.composer {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) minmax(90px, 130px) 92px;
  gap: 10px;
  align-items: end;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.composer input,
.composer select {
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  padding: 0 14px;
  min-width: 0;
  width: 100%;
  height: 46px;
  background: white;
  color: var(--ink);
}
.composer textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  padding: 12px 14px;
  min-width: 0;
  width: 100%;
  min-height: 46px;
  max-height: 160px;
  background: white;
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
  scrollbar-width: thin;
}
.composer button {
  height: 46px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  font-weight: 800;
}
.composer-icon-btn {
  width: 48px;
  padding: 0 !important;
  font-size: 20px;
  line-height: 1;
}
.composer-file-select {
  color: var(--muted);
  font-size: 12.5px;
  text-overflow: ellipsis;
}
.composer-file-select.is-empty {
  color: #98a2b3;
}
.delivery-error {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f2;
  color: #b42318;
  font-size: 12px;
  line-height: 1.7;
}
.customer-card h2 { margin-bottom: 8px; }
.info-list { display: grid; gap: 12px; margin: 18px 0; }
.info-list div { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); }
.info-list b { color: var(--ink); text-align: left; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action-grid button {
  min-height: 40px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  color: #175cd3;
}

.control-grid { grid-template-columns: repeat(2, minmax(260px, 1fr)); }
.control-grid .wide { grid-column: 1 / -1; }
.mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 12px;
}
.mini-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fcfcfd;
}
.mini-card b { display: block; font-size: 24px; color: var(--blue); }
ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.check-list li::before { content: "✓"; color: var(--green); margin-inline-end: 8px; }

.reports-grid, .settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 16px;
}
.report-card, .settings-grid article {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  min-height: 120px;
}
.report-card b { display: block; font-size: 30px; color: var(--green); margin-bottom: 8px; }
.settings-grid article b { display: block; font-size: 18px; margin-bottom: 8px; }
.settings-grid article span { color: var(--muted); line-height: 1.7; }
.settings-workspace {
  grid-column: 1 / -1;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.settings-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 16px;
}
.settings-toolbar button, .primary-btn {
  border: 1px solid #175cd3;
  background: #175cd3;
  color: white;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
}
.permissions-layout {
  display: grid;
  grid-template-columns: minmax(220px, .8fr) minmax(220px, .8fr) minmax(360px, 1.5fr);
  gap: 16px;
}
.settings-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fcfcfd;
  padding: 16px;
  min-width: 0;
}
.settings-panel h3 {
  margin: 0 0 14px;
  font-size: 17px;
}
.settings-panel select, .settings-panel input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 12px;
  background: white;
}
.field-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin: 14px 0 7px;
}
.employee-permission-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
  margin-top: 12px;
  display: grid;
  gap: 5px;
}
.employee-permission-card span, .employee-permission-card small {
  color: var(--muted);
}
.settings-panel button {
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--line);
  background: white;
  color: #175cd3;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 12px;
}
.settings-panel .primary-btn {
  background: #175cd3;
  border-color: #175cd3;
  color: white;
}
.role-list {
  display: grid;
  gap: 10px;
}
.role-item {
  text-align: right;
  display: grid;
  gap: 5px;
}
.role-item.active {
  border-color: #175cd3;
  background: #eff6ff;
}
.role-item span {
  color: var(--muted);
  font-size: 13px;
}
.permission-editor {
  background: white;
}
.permission-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.permission-editor-head span {
  display: block;
  color: var(--muted);
  margin-top: 5px;
}
.permission-editor-head em {
  color: #067647;
  background: #ecfdf3;
  border: 1px solid #abefc6;
  border-radius: 999px;
  padding: 5px 10px;
  font-style: normal;
  font-size: 12px;
  white-space: nowrap;
}
.permission-editor-head .danger-btn {
  width: auto;
  margin: 0;
  color: #b42318;
  border-color: #fecdca;
  background: #fff1f3;
}
.permission-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.permission-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fcfcfd;
}
.permission-group h4 {
  margin: 0 0 10px;
  font-size: 14px;
}
.permission-check {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: #344054;
}
.permission-check input {
  width: 16px;
  min-height: 16px;
  accent-color: #175cd3;
}
.permissions-empty {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: white;
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
}
.meta-settings-workspace {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}
.backup-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 16px;
}
.backup-actions {
  display: grid;
  grid-template-columns: minmax(180px, max-content) minmax(160px, max-content) 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.backup-actions button,
.backup-item-actions button {
  min-height: 40px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 0 14px;
  color: #175cd3;
}
.backup-actions .primary-btn {
  background: #175cd3;
  border-color: #175cd3;
  color: white;
}
.backup-actions small {
  color: var(--muted);
}
.backup-list {
  display: grid;
  gap: 10px;
}
.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fcfcfd;
}
.backup-item b,
.backup-item span {
  display: block;
}
.backup-item b {
  overflow-wrap: anywhere;
}
.backup-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}
.backup-item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.backup-item-actions .danger-btn {
  color: #b42318;
  border-color: #fecdca;
  background: #fff1f3;
}
.factory-intel-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 16px;
}
.factory-intel-form label {
  color: var(--muted);
  font-size: 13px;
  display: grid;
  gap: 7px;
}
.factory-intel-form input,
.factory-intel-form button {
  min-height: 40px;
}
.factory-intel-form button {
  border: 1px solid #175cd3;
  background: #175cd3;
  color: white;
  border-radius: 8px;
}
.factory-intel-form small {
  align-self: center;
  color: var(--muted);
}
.factory-intel-log-head {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.factory-intel-log-head div {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.factory-intel-log-head button {
  min-height: 38px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 0 12px;
  color: #175cd3;
}
.factory-intel-logs {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}
.factory-intel-log {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 12px;
  display: grid;
  gap: 8px;
}
.factory-intel-log.suggested {
  border-color: #fed7aa;
  background: #fff7ed;
}
.factory-intel-log.auto_applied {
  border-color: #abefc6;
  background: #ecfdf3;
}
.factory-intel-log b,
.factory-intel-log span,
.factory-intel-log small,
.factory-intel-log em {
  display: block;
}
.factory-intel-log span,
.factory-intel-log small,
.factory-intel-log em {
  color: var(--muted);
  font-size: 13px;
}
.factory-intel-log p {
  margin: 0;
}
.factory-intel-log blockquote {
  margin: 0;
  border-right: 3px solid #175cd3;
  padding: 8px 10px;
  background: #f8fafc;
  color: #344054;
}
.factory-intel-log button {
  justify-self: start;
  min-height: 36px;
  border: 1px solid #fecdca;
  background: #fff1f3;
  color: #b42318;
  border-radius: 8px;
  padding: 0 12px;
}
.conversation-item .factory-intel-inline {
  margin-top: 10px;
  border: 1px solid #d0d5dd;
  background: #f8fafc;
  border-radius: 8px;
  padding: 9px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  overflow-wrap: break-word;
  word-break: break-word;
  display: grid;
  gap: 5px;
  text-align: right;
}
.conversation-item .factory-intel-inline.auto_applied {
  border-color: #abefc6;
  background: #ecfdf3;
}
.conversation-item .factory-intel-inline.suggested {
  border-color: #fed7aa;
  background: #fff7ed;
}
.conversation-item .factory-intel-inline.muted {
  color: var(--muted);
  font-size: 12px;
}
.factory-intel-inline div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.factory-intel-inline b,
.factory-intel-inline span {
  font-size: 12px;
  min-width: 0;
  overflow-wrap: break-word;
}
.factory-intel-inline small,
.factory-intel-inline p {
  font-size: 12px;
  color: #475467;
}
.factory-intel-inline p {
  margin: 0;
  line-height: 1.5;
  overflow-wrap: break-word;
}
.factory-intel-card-undo {
  justify-self: start;
  border: 1px solid #fecdca;
  background: #fff1f3;
  color: #b42318;
  border-radius: 999px;
  padding: 4px 9px;
}
.meta-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1.25fr) minmax(260px, .85fr) minmax(260px, .85fr);
  gap: 16px;
}
.meta-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
}
.meta-fields label {
  color: var(--muted);
  font-size: 13px;
  display: grid;
  gap: 7px;
}
.meta-fields input {
  color: var(--ink);
}
.safe-mode-check {
  grid-template-columns: 18px 1fr !important;
  align-items: center;
  color: var(--ink) !important;
}
.safe-mode-check input {
  width: 16px;
  min-height: 16px;
  accent-color: #175cd3;
}
.meta-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.meta-actions button, .meta-tools button {
  margin-top: 0;
}
.meta-result {
  margin: 12px 0 0;
  background: #101828;
  color: #e6eef8;
  border-radius: 8px;
  padding: 12px;
  min-height: 150px;
  overflow: auto;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
}
.meta-status-pill {
  border: 1px solid #abefc6;
  background: #ecfdf3;
  color: #067647;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}
.meta-status-pill.failed {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #c2410c;
}
.status-details {
  display: grid;
  gap: 10px;
}
.status-details div {
  border-bottom: 1px solid #eef2f6;
  padding-bottom: 9px;
  display: grid;
  gap: 4px;
}
.status-details span {
  color: var(--muted);
  font-size: 12px;
}
.status-details b {
  overflow-wrap: anywhere;
}
.meta-health-check .hint-text {
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0 12px;
}
.health-check-list {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}
.health-check-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
  font-size: 13px;
}
.health-check-item.failed {
  border-color: #fed7aa;
  background: #fff7ed;
}
.health-check-item small {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.meta-health-check .danger-btn {
  margin-top: 4px;
}
.meta-logs-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.log-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
}
.log-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
  display: grid;
  gap: 5px;
}
.log-item b {
  font-size: 13px;
  overflow-wrap: anywhere;
}
.log-item span, .log-empty {
  color: var(--muted);
  font-size: 12px;
}
button:disabled, input:disabled, select:disabled {
  cursor: not-allowed;
  opacity: .58;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  width: min(620px, calc(100vw - 40px));
}
dialog::backdrop { background: rgba(16, 24, 40, .35); }
.wide-dialog {
  width: min(760px, calc(100vw - 36px));
  max-height: min(680px, calc(100vh - 64px));
  padding: 0;
}
.wide-dialog[open] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.new-message-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  max-height: 100%;
}
.new-message-form > h2 {
  margin: 0;
  padding: 20px 24px 12px;
}
.new-message-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 14px 16px;
  padding: 4px 24px 16px;
  overflow-y: auto;
  min-height: 0;
}
.new-message-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}
.new-message-grid input,
.new-message-grid select,
.new-message-grid textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: 0;
  background: white;
  color: var(--ink);
  font: inherit;
}
.wide-field {
  grid-column: 1 / -1;
}
.new-message-grid label:has(#newMessageFile) {
  grid-column: 1 / -1;
}
.shared-file-admin {
  border: 1px dashed #bfdbfe;
  border-radius: 8px;
  background: #f8fbff;
  padding: 12px;
  display: grid;
  gap: 10px;
  margin: 0 24px 16px;
}
.shared-file-upload-row {
  display: grid;
  grid-template-columns: 1fr 1fr max-content;
  gap: 8px;
  align-items: center;
}
.shared-file-upload-row input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.form-notice {
  min-height: 20px;
  color: var(--muted);
  margin: 0;
}
.dialog-actions {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  background: white;
}
.dialog-actions .form-notice {
  flex: 1;
}
.template {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 10px 0;
}
.template p { line-height: 1.7; }

.employee-create-item {
  list-style: none;
  margin-block-end: 14px;
}
.employee-create-form {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}
.employee-create-form input,
.employee-create-form select {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 10px;
  background: white;
}
.employee-create-form button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  background: #175cd3;
  color: white;
  font-weight: 700;
}
.employee-create-form small {
  min-height: 18px;
  color: var(--muted);
}
.employee-admin-card {
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-block: 10px;
  background: white;
  display: grid;
  gap: 10px;
}
.employee-archived {
  opacity: .72;
  background: #f8fafc;
}
.employee-admin-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}
.account-badge {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  background: #f2f4f7;
  color: #344054;
  white-space: nowrap;
}
.account-badge.active {
  background: #ecfdf3;
  color: #067647;
}
.account-badge.disabled {
  background: #fff7ed;
  color: #c2410c;
}
.employee-edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
}
.employee-edit-grid input,
.employee-edit-grid select {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 36px;
  padding: 0 10px;
}
.employee-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.employee-actions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  min-height: 36px;
  padding: 0 12px;
}
.employee-actions button:first-child {
  border-color: #175cd3;
  background: #175cd3;
  color: white;
}
.departments-admin {
  display: grid;
  gap: 14px;
}
.department-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 70px auto;
  gap: 10px;
  align-items: center;
}
.department-form input,
.department-form button,
.department-admin-card input,
.department-admin-card button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 10px;
}
.department-form button,
.department-admin-card button {
  background: white;
}
.department-admin-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 10px;
}
.department-admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
  display: grid;
  gap: 8px;
}
.department-admin-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}
.department-archived {
  opacity: .68;
  background: #f8fafc;
}
.account-password-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr)) auto;
  gap: 10px;
  align-items: center;
}
.account-password-form input,
.account-password-form button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 10px;
}
.account-password-form button {
  border-color: #175cd3;
  background: #175cd3;
  color: white;
  font-weight: 700;
}
.account-password-form small {
  grid-column: 1 / -1;
  color: var(--muted);
}
.bot-settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
}
.bot-settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}
.bot-settings-form label:nth-of-type(3),
.bot-settings-form label:nth-of-type(4),
.bot-settings-form label:nth-of-type(5),
.bot-settings-form label:nth-of-type(6) {
  grid-column: 1 / -1;
}
.bot-settings-form input,
.bot-settings-form textarea,
.bot-settings-form button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 40px;
  padding: 9px 10px;
  font: inherit;
}
.bot-settings-form textarea {
  min-height: 112px;
  resize: vertical;
}
.bot-settings-form button {
  border-color: #175cd3;
  background: #175cd3;
  color: white;
  font-weight: 700;
}
.bot-settings-form small {
  align-self: center;
  color: var(--muted);
}
.factory-status-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 72px auto;
  gap: 10px;
  align-items: center;
}
.factory-status-form input,
.factory-status-form button,
.factory-status-card input,
.factory-status-card button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 10px;
}
.factory-status-form button,
.factory-status-actions button:first-child {
  border-color: #175cd3;
  background: #175cd3;
  color: white;
  font-weight: 700;
}
.factory-status-form small {
  grid-column: 1 / -1;
  color: var(--muted);
}
.factory-status-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.factory-status-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
  display: grid;
  gap: 8px;
}
.factory-status-head,
.factory-status-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.factory-status-head span,
.factory-status-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}
.factory-status-head em {
  border-radius: 999px;
  background: #f2f4f7;
  color: #344054;
  font-size: 12px;
  font-style: normal;
  padding: 4px 8px;
  white-space: nowrap;
}
.factory-status-actions button {
  background: white;
}
.factory-status-archived {
  opacity: .68;
  background: #f8fafc;
}
.platform-sync-form {
  display: grid;
  gap: 12px;
}
.platform-sync-form > label:not(.safe-mode-check) {
  display: grid;
  gap: 6px;
  color: var(--muted);
}
.platform-sync-form input,
.platform-sync-form button,
.platform-factory-link input,
.platform-factory-link button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 10px;
}
.platform-sync-form button,
.platform-factory-link button {
  border-color: #175cd3;
  background: #175cd3;
  color: white;
  font-weight: 700;
}
.platform-sync-map {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 10px;
}
.platform-sync-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 6px;
  background: #fff;
}
.platform-sync-row span,
.platform-sync-form small,
.platform-factory-link small {
  color: var(--muted);
  font-size: 12px;
}
.platform-sync-logs {
  margin-top: 16px;
}
.platform-sync-log {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
  background: #f8fafc;
  display: grid;
  gap: 6px;
}
.platform-sync-log div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.platform-sync-log span,
.platform-sync-log small {
  color: var(--muted);
  font-size: 12px;
}
.platform-factory-link {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-top: 14px;
  display: grid;
  gap: 8px;
  background: #f8fafc;
}
.platform-factory-link label {
  font-weight: 700;
}

.file-library-workspace {
  display: grid;
  gap: 18px;
}
.file-library-upload {
  display: grid;
  gap: 14px;
}
.file-library-upload .panel-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}
.file-library-upload .panel-head span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}
.file-upload-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1.1fr auto;
  gap: 12px;
  align-items: end;
}
.file-upload-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}
.file-upload-grid input,
.file-upload-grid select {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}
.file-upload-grid input[type="file"] {
  padding: 8px 10px;
}
.file-upload-grid button {
  border: 1px solid #175cd3;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 18px;
  background: #175cd3;
  color: #fff;
  font-weight: 800;
}
.file-library-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}
.file-dept-card {
  border: 1px solid var(--line);
  border-top: 3px solid var(--dept-color, var(--blue));
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.file-dept-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--dept-color, var(--blue)) 8%, #fff);
}
.file-dept-head b {
  display: block;
  color: var(--ink);
  font-size: 18px;
}
.file-dept-head span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}
.file-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}
.file-row {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}
.file-row > div:first-child {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.file-row b,
.file-row > div:first-child span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-row > div:first-child span {
  color: var(--muted);
  font-size: 13px;
}
.file-meta {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 145px;
}
.file-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
}
.file-empty,
.file-library-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  min-height: 92px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  background: #fbfcfe;
}
.file-library-empty {
  gap: 6px;
  padding: 22px;
}
.file-library-empty b {
  color: var(--ink);
}

@media (max-width: 1400px) {
  .chat-panel .composer {
    grid-template-columns: 48px minmax(0, 1fr) 88px;
  }
  .chat-panel .composer-file-select {
    grid-column: 1 / -1;
  }
}

@media (max-width: 1200px) {
  .daily-counters { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
  .department-grid { grid-template-columns: repeat(3, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 180px minmax(520px, 1fr); }
  .chat-panel { display: none; }
  .chat-layout.mobile-chat-active { grid-template-columns: 1fr; }
  .chat-layout.mobile-chat-active .filters,
  .chat-layout.mobile-chat-active .conversation-list { display: none; }
  .chat-layout.mobile-chat-active .chat-panel { display: flex; }
  .mobile-back-btn { display: inline-flex; }
  .chat-head { align-items: center; }
  .customer-card { display: none; }
  .permissions-layout { grid-template-columns: 1fr 1fr; }
  .permission-editor { grid-column: 1 / -1; }
  .meta-layout, .meta-logs-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: static; width: auto; min-height: auto; }
  .shell { margin-inline-start: 0; }
  .topbar { position: static; height: auto; padding: 14px; align-items: stretch; flex-direction: column; }
  .search { width: 100%; }
  .page-head { flex-direction: column; }
  .daily-counters { grid-template-columns: repeat(2, minmax(130px, 1fr)); width: 100%; }
  .metric-card { min-height: 68px; }
  .row { grid-template-columns: 1fr; align-items: start; }
  .row button { width: max-content; }
  .department-grid, .dashboard-grid, .control-grid, .reports-grid, .settings-grid { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .conversation-board { grid-template-columns: 1fr; }
  .filters { display: none; }
  .conversation-list { max-height: none; }
  .chat-panel { min-height: 560px; }
  .composer { grid-template-columns: 44px 1fr 86px; }
  .composer-file-select { grid-column: 1 / -1; min-height: 42px; }
  .new-message-grid, .shared-file-upload-row { grid-template-columns: 1fr; }
  .settings-toolbar, .permission-editor-head { flex-direction: column; }
  .permissions-layout, .permission-groups, .meta-layout, .meta-fields, .meta-actions, .meta-logs-grid, .factory-status-list, .factory-status-form, .platform-sync-map, .file-library-grid, .file-upload-grid { grid-template-columns: 1fr; }
  .file-library-upload .panel-head, .file-row { flex-direction: column; }
  .file-meta { min-width: 0; justify-content: flex-start; }
}

/* Employee page visual polish only */
.control-grid:has(#employeeAdmin) {
  grid-template-columns: minmax(420px, .95fr) minmax(560px, 1.05fr);
  gap: 18px;
}

.panel:has(#criticalCards),
.panel:has(#systemStats),
.panel:has(#employeeAdmin),
.panel:has(#auditLog) {
  box-shadow: 0 12px 30px rgba(16, 24, 40, .045);
}

.panel:has(#employeeAdmin) {
  max-height: calc(100vh - 170px);
  overflow: hidden;
}

#employeeAdmin {
  max-height: calc(100vh - 255px);
  overflow-y: auto;
  padding-inline-end: 6px;
  gap: 14px;
}

#employeeAdmin::-webkit-scrollbar,
#auditLog::-webkit-scrollbar {
  width: 7px;
}

#employeeAdmin::-webkit-scrollbar-track,
#auditLog::-webkit-scrollbar-track {
  background: transparent;
}

#employeeAdmin::-webkit-scrollbar-thumb,
#auditLog::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

.employee-create-form {
  border-color: #dbe7ff;
  background: #f8fbff;
  padding: 14px;
}

.employee-create-form button {
  min-height: 42px;
}

.employee-admin-card {
  padding: 14px;
  border-color: #e4e7ec;
  box-shadow: 0 6px 18px rgba(16, 24, 40, .035);
}

.employee-admin-head {
  padding-bottom: 2px;
}

.employee-admin-head b {
  font-size: 16px;
}

.employee-edit-grid {
  gap: 10px;
}

.employee-actions {
  justify-content: flex-start;
  padding-top: 2px;
}

.panel:has(#auditLog) {
  grid-column: 1 / -1;
}

#auditLog {
  max-height: 420px;
  overflow-y: auto;
  padding-inline-end: 6px;
}

#auditLog .row {
  grid-template-columns: minmax(180px, .75fr) minmax(320px, 1.5fr) minmax(120px, .45fr) minmax(90px, .35fr);
  padding: 13px 0;
}

#criticalCards .mini-card,
#systemStats .mini-card {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.template-hint {
  grid-column: 1 / -1;
  margin: -6px 0 0;
  color: #64748b;
  font-size: 13px;
  line-height: 1.8;
  text-align: right;
}

.new-message-form textarea.is-readonly {
  background: #f8fafc;
  color: #334155;
  cursor: default;
}

@media (max-width: 860px) {
  .control-grid:has(#employeeAdmin) {
    grid-template-columns: 1fr;
  }

  .panel:has(#employeeAdmin),
  #employeeAdmin,
  #auditLog {
    max-height: none;
  }
}
