:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1f2937;
  --urgent: #b91c1c;
  --warning: #c2410c;
  --ok: #15803d;
  --done: #6b7280;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: 14px;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: 220px; height: 100vh;
  background: #7A9BB0;
  display: flex; flex-direction: column;
  z-index: 200;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
}
.sidebar-brand-icon {
  font-size: 18px; width: 34px; height: 34px;
  background: rgba(255,255,255,0.20); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-brand-name { font-size: 14px; font-weight: 700; color: #1a2e3b; }
.sidebar-brand-sub { font-size: 10px; color: rgba(26,46,59,0.55); margin-top: 1px; }
.sidebar-nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.sidebar-section {
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  color: rgba(26,46,59,0.62); text-transform: uppercase;
  padding: 14px 8px 5px;
}
.sidebar-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 7px;
  color: rgba(26,46,59,0.88); text-decoration: none;
  font-size: 13px; font-weight: 500;
  transition: background 0.12s, color 0.12s;
  margin-bottom: 1px;
  border-left: 3px solid transparent;
}
.sidebar-item:hover { background: rgba(26,46,59,0.10); color: #1a2e3b; }
.sidebar-item.active { background: rgba(26,46,59,0.14); color: #1a2e3b; border-left-color: #1a2e3b; }
.sidebar-item-soon { opacity: .45; cursor: default; }
.sidebar-item-soon:hover { background: none; color: rgba(26,46,59,0.72); }
.sidebar-soon-badge { margin-left: auto; font-size: 9px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; background: rgba(26,46,59,0.12); color: rgba(26,46,59,0.55); padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.sidebar-icon { font-size: 17px; width: 20px; text-align: center; flex-shrink: 0; line-height: 1; }
.sidebar-footer {
  padding: 12px 14px; border-top: 1px solid rgba(26,46,59,0.15);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  flex-shrink: 0;
}
.sidebar-user { display: flex; align-items: center; gap: 9px; min-width: 0; }
.sidebar-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: #1a2e3b; color: #fff;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-user-info { min-width: 0; }
.sidebar-username { font-size: 12px; font-weight: 600; color: #1a2e3b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-role { font-size: 10px; color: rgba(26,46,59,0.55); }
.sidebar-logout {
  color: rgba(26,46,59,0.45); text-decoration: none;
  display: flex; align-items: center; justify-content: center;
  padding: 6px; border-radius: 6px; flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}
.sidebar-logout:hover { color: #1a2e3b; background: rgba(26,46,59,0.10); }

/* ── Layout ── */
.has-sidebar .container { margin-left: 220px; }
.container { max-width: 1600px; margin: 0 auto; padding: 24px 20px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ── KPIs ── */
.dash-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.kpis { display: flex; gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; min-width: 80px; text-align: center; }
.kpi .n { display: block; font-size: 26px; font-weight: 700; }
.kpi .l { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-urgent .n { color: var(--urgent); }
.kpi-warning .n { color: var(--warning); }
.kpi-total .n { color: var(--primary); }
.kpi-immediat .n { color: #7c3aed; }
a.kpi { text-decoration: none; cursor: pointer; transition: box-shadow 0.15s, transform 0.1s; }
a.kpi:hover { box-shadow: 0 0 0 2px var(--line); transform: translateY(-1px); }
a.kpi.kpi-active { box-shadow: 0 0 0 2px currentColor; }

/* ── Filters ── */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.filters select, .filters input[type=text] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; background: var(--card);
}

/* ── Table ── */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
thead th { background: #f1f5f9; text-align: left; padding: 10px; font-size: 12px; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
a.sort-th { color: inherit; text-decoration: none; }
.btn-danger { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; }
.btn-warning { background: #fef9c3; color: #854d0e; border-color: #fde047; }
.btn-warning:hover { background: #fef08a; }
a.sort-th:hover { color: var(--primary); }
tbody td { padding: 0; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #f8fafc; }
.td-link { display:block; padding:10px; color:inherit; text-decoration:none; }
tbody tr.row-urgent { background: #fef2f2; }
tbody tr.row-warning { background: #fff7ed; }

/* ── Priority dot ── */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot-urgent { background: var(--urgent); box-shadow: 0 0 0 3px #fee2e2; }
.dot-warning { background: var(--warning); box-shadow: 0 0 0 3px #ffedd5; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px #dcfce7; }
.dot-done { background: var(--done); }

/* ── Priority badges ── */
.badge-urgent { display: inline-block; background: #fee2e2; color: #991b1b; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge-warning { display: inline-block; background: #ffedd5; color: #9a3412; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge-ok { display: inline-block; background: #dcfce7; color: #166534; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge-done { display: inline-block; background: #f3f4f6; color: var(--muted); font-size: 12px; padding: 2px 8px; border-radius: 999px; }

/* ── Buttons ── */
.btn { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px; text-decoration: none; display: inline-block; }
.btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #374151; }
.btn-danger { color: var(--urgent); border-color: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Flash ── */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ── Login ── */
.login-card { max-width: 360px; margin: 60px auto; background: var(--card); padding: 28px; border: 1px solid var(--line); border-radius: 12px; }
.login-card h1 { margin-bottom: 4px; }
.login-card label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.login-card input { display: block; width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }

/* ── Tags ── */
.tag { display: inline-block; background: #e5e7eb; color: #374151; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.tag-on { background: #dcfce7; color: #166534; }
.tag-off { background: #f3f4f6; color: var(--muted); }
.tag-admin { background: #dbeafe; color: #1e40af; }
.tag-warn { background: #fef9c3; color: #854d0e; }
.tag-ai { background: #ede9fe; color: #5b21b6; font-size: 10px; }

/* ── Thread messages ── */
.messages-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 28px; }
.msg { max-width: 80%; padding: 12px 16px; border-radius: 12px; }
.msg-in { background: var(--card); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg-out { background: #dbeafe; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg-out .msg-meta { flex-direction: row-reverse; }
.msg-out .msg-sender { color: #1d4ed8; }
.msg-operator { background: #fefce8; border: 1px solid #fde047; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg-operator .msg-sender { color: #854d0e; }
.msg-system { background: var(--bg); border: 1px dashed var(--line); align-self: center; max-width: 90%; opacity: .75; border-radius: 8px; }
.msg-system .msg-sender { color: var(--muted); font-weight: 500; font-size: 12px; }
.msg-system .msg-body { font-size: 13px; color: var(--muted); }
.msg-meta { display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.msg-sender { font-weight: 700; font-size: 13px; }
.msg-time { font-size: 11px; color: var(--muted); }
.msg-body { white-space: pre-wrap; line-height: 1.5; font-size: 14px; }

/* ── Reply zone ── */
.reply-zone { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-top: 8px; }
.reply-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.reply-tab { background: none; border: 1px solid transparent; border-radius: 8px; padding: 6px 14px; cursor: pointer; font-size: 13px; color: var(--muted); }
.reply-tab:hover { background: var(--bg); border-color: var(--line); }
.reply-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.reply-textarea { width: 100%; min-height: 140px; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; font-family: inherit; resize: vertical; margin-top: 10px; }
.reply-textarea:focus { outline: none; border-color: #6b7280; box-shadow: 0 0 0 3px rgba(31,41,55,.08); }
.reply-actions { display: flex; gap: 8px; margin-top: 10px; }
.attach-zone { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.attach-label { cursor: pointer; }
.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.att-chip { display: inline-flex; align-items: center; gap: 4px; background: #f1f5f9; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; font-size: 12px; text-decoration: none; color: var(--primary); }
.att-chip:hover { background: #e2e8f0; }
.att-local { color: var(--muted); cursor: default; }
.mode-panel { margin-bottom: 4px; }

/* ── Forms ── */
.conn-form { max-width: 1120px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 24px; margin-top: 16px; }
.field { display: block; margin-bottom: 18px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.req { color: var(--urgent); font-style: normal; }
.conn-form input[type=text],
.conn-form input[type=url],
.conn-form input[type=password],
.conn-form select { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; background: #fff; }
.masked { -webkit-text-security: disc; text-security: disc; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--line); }
.form-section { border: none; padding: 0; margin-bottom: 24px; }
.checkbox-inline { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.checkbox-inline input { width: auto; margin: 0; }

/* ── Add form ── */
.add-form { margin-top: 16px; }
.add-form summary { cursor: pointer; color: var(--primary); font-weight: 600; padding: 8px 0; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-top: 12px; align-items: end; }
.grid-form label { display: block; font-size: 13px; color: var(--muted); }
.grid-form input, .grid-form select { display: block; width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }

/* ── Thread two-column layout ── */
.thread-layout { display: flex; gap: 20px; align-items: flex-start; }
.thread-main { flex: 1; min-width: 0; }
.thread-aside {
  width: 380px; flex-shrink: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; position: sticky; top: 24px;
  max-height: calc(100vh - 48px); overflow-y: auto;
}
.aside-title { font-size: 14px; font-weight: 700; margin: 0 0 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.aside-section { padding: 10px 0; border-bottom: 1px solid var(--line); }
.aside-section:last-child { border-bottom: none; }
.aside-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; margin-bottom: 6px; }
.aside-block { font-size: 13px; line-height: 1.6; margin-bottom: 6px; }
.aside-row { display: flex; gap: 8px; align-items: baseline; font-size: 13px; margin-top: 4px; }
.aside-key { color: var(--muted); font-size: 12px; min-width: 90px; flex-shrink: 0; }
.order-line { margin-bottom: 8px; }
.order-line:last-child { margin-bottom: 0; }
.order-line-title { font-size: 13px; font-weight: 600; line-height: 1.4; }
.order-line-price { font-size: 13px; color: var(--ink); margin-top: 2px; }

/* ── Searchable select ── */
.ss-wrap { position: relative; display: inline-block; min-width: 160px; }
.ss-display {
  padding: 7px 28px 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; background: var(--card); cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; user-select: none;
}
.ss-display::after {
  content: "▾"; position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none; font-size: 11px;
}
.ss-dropdown {
  position: absolute; top: calc(100% + 3px); left: 0; right: 0; z-index: 999;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.10); overflow: hidden;
}
.ss-input {
  width: 100%; padding: 8px 10px; border: none; border-bottom: 1px solid var(--line);
  font-size: 13px; outline: none; background: var(--bg); box-sizing: border-box;
}
.ss-list { list-style: none; margin: 0; padding: 4px 0; max-height: 220px; overflow-y: auto; }
.ss-option {
  padding: 8px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.ss-option:hover { background: var(--bg); }
.ss-option.ss-selected { font-weight: 600; color: var(--primary); }
.ss-empty { padding: 8px 12px; font-size: 12px; color: var(--muted); }

/* ── Misc ── */
.empty { color: var(--muted); padding: 20px; background: var(--card); border: 1px dashed var(--line); border-radius: 10px; }
.wide-input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.inline-form { display: flex; gap: 6px; align-items: center; margin: 0; }
