:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --line: #dbe3ef;
  --text: #162235;
  --muted: #5f6c80;
  --primary: #1890ff;
  --primary-soft: #e6f4ff;
  --ok: #52c41a;
  --warn: #faad14;
  --danger: #f5222d;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Inter, Roboto, -apple-system, sans-serif; background: var(--bg); color: var(--text); }
.layout { display: grid; grid-template-columns: 330px 1fr; min-height: 100vh; position: relative; }
.sidebar {
  background: #0f1a2d; color: #d8e1f1; padding: 20px 16px; overflow-y: auto; z-index: 30;
  transition: transform .3s ease-in-out;
}
.sidebar-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.sidebar-close { border: 0; background: transparent; color: #d8e1f1; font-size: 20px; cursor: pointer; display: none; }
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(10,18,34,.38); opacity: 0; pointer-events: none; transition: opacity .3s ease-in-out; z-index: 20;
}
.layout.sidebar-mobile-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; background: var(--primary); display: grid; place-items: center; font-weight: 800; }
.brand-title { font-weight: 700; font-size: 14px; }
.brand-subtitle { font-size: 12px; color: #9fb1cd; }
.section-title { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #8fa4c6; margin: 16px 8px 8px; }
.menu-item { width: 100%; background: transparent; border: 1px solid transparent; color: #d8e1f1; text-align: left; border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; cursor: pointer; }
.menu-item:hover, .menu-item.active { background: #15243e; border-color: #2a3c5f; }
.tree { display: grid; gap: 4px; }
.tree-row { width: 100%; padding: 8px 12px; border-radius: 8px; cursor: pointer; border: 0; background: transparent; color: inherit; text-align: left; }
.tree-row:hover { background: #172847; }
.tree-row.active { background: #22385f; }
.tree-row.level-1 { padding-left: 26px; font-size: 14px; color: #c8d4ea; }
.tree-row.level-2 { padding-left: 40px; font-size: 13px; color: #aebfde; }
.tree-row.level-3 { padding-left: 54px; font-size: 13px; color: #aebfde; }
.tree-row.level-4 { padding-left: 68px; font-size: 13px; color: #aebfde; }

.content { padding: 20px 24px; }
.header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.header h1 { font-size: 24px; margin-right: auto; }
.mobile-only { display: none; }
button { font: inherit; }
.primary, .ghost { border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer; }
.primary { background: var(--primary); color: #fff; }
.ghost { background: #fff; border: 1px solid var(--line); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(12, 1fr); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; } .col-6 { grid-column: span 6; } .col-8 { grid-column: span 8; } .col-12 { grid-column: span 12; }
.card h3 { margin-bottom: 10px; font-size: 16px; }
.tag { display: inline-block; font-size: 12px; background: var(--primary-soft); color: var(--primary); padding: 4px 8px; border-radius: 999px; margin-bottom: 8px; }
.metric { font-size: 14px; color: var(--muted); margin: 8px 0; }
.notice { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #f8fbff; font-size: 13px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { border-bottom: 1px solid var(--line); text-align: left; padding: 8px 6px; }
.table th { color: var(--muted); font-weight: 600; }
.table-wrap { width: 100%; overflow: auto; }
.table-sticky-head thead th { position: sticky; top: 0; background: #fff; z-index: 2; }
.ird-inline-input { width: 100%; min-width: 130px; }
.hidden { display: none; }
.section-row td { background: #f7faff; font-weight: 600; color: #304666; }
.row-actions { display: flex; gap: 6px; align-items: center; }
.mini { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 12px; }
.mini.danger { border-color: #f2b8b5; color: #b42318; background: #fff5f4; }
.actions-dropdown { position: relative; display: inline-flex; margin-left: auto; }
.actions-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 55;
  min-width: 190px;
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .14);
}
.actions-dropdown.open .actions-dropdown-menu { display: flex; }
.actions-dropdown-menu .mini { width: 100%; text-align: left; }

.dashboard-toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.status-line { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); }
.connection.online { color: var(--ok); }
.connection.offline { color: var(--danger); }
.spinner { width: 14px; height: 14px; border: 2px solid #c7d6eb; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
.spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.dashboard-grid { display: grid; gap: 14px; grid-template-columns: repeat(1, minmax(0, 1fr)); }
@media (min-width: 640px) { .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .dashboard-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1600px) { .dashboard-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.dashboard-card { border-radius: 12px; position: relative; }
.card-remove { position: absolute; right: 10px; top: 10px; border: 0; background: transparent; color: #8a97aa; cursor: pointer; font-size: 16px; }
.kv { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.progress { height: 8px; background: #ecf1fa; border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), #5f8bff); }
.status-pill { display: inline-block; border-radius: 999px; padding: 4px 10px; font-size: 12px; color: #fff; margin-top: 10px; }
.status-pill.ok { background: var(--ok); }
.status-pill.warn { background: var(--warn); }
.status-pill.danger { background: var(--danger); }
.mini-chart { display: grid; grid-template-columns: repeat(10,1fr); gap: 3px; align-items: end; height: 34px; margin-top: 8px; }
.mini-chart span { background: #91caff; border-radius: 2px; }

.modal { position: fixed; inset: 0; display: none; z-index: 40; }
.modal.open { display: block; }
.overlay { position: absolute; inset: 0; background: rgba(10, 18, 34, .35); }
.dialog { position: relative; z-index: 1; width: min(640px, calc(100% - 32px)); margin: 8vh auto; background: #fff; border-radius: 14px; padding: 18px; max-height: 84vh; overflow-y: auto; }
.dialog h3 { margin-bottom: 12px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.form-grid { display: grid; gap: 10px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid label { display: block; font-size: 13px; color: var(--muted); }
.form-grid input, .form-grid textarea, .form-grid select { width: 100%; margin-top: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.form-grid .auto-calculated { border-color: #3b82f6; background: #eff6ff; }
.gantt-wrap { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 12px; background: #fcfdff; }
.gantt-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.gantt-row { display: grid; grid-template-columns: 220px 1fr 190px; gap: 10px; align-items: center; margin: 6px 0; }
.gantt-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-track { position: relative; height: 18px; border-radius: 8px; background: #eef2ff; }
.gantt-bar { position: absolute; top: 2px; height: 14px; border-radius: 7px; background: #6366f1; overflow: hidden; min-width: 4px; }
.gantt-bar span { display: block; height: 100%; background: #22c55e; opacity: 0.7; }
.gantt-dates { font-size: 12px; color: var(--muted); text-align: right; }
.radio-row { display: flex; gap: 14px; flex-wrap: wrap; }

@media (max-width: 1023px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(86vw, 330px); transform: translateX(-100%);
  }
  .layout.sidebar-mobile-open .sidebar { transform: translateX(0); }
  .sidebar-close, .mobile-only { display: inline-block; }
  .col-3, .col-4, .col-6, .col-8 { grid-column: span 12; }
}

.ai-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: 0;
  background: var(--primary);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(24, 144, 255, .34);
  z-index: 60;
}
.ai-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(420px, calc(100vw - 24px));
  height: min(640px, calc(100vh - 32px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(22, 34, 53, .2);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.ai-widget.min { height: 52px; overflow: hidden; }
.ai-head { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ai-head-actions { display: flex; gap: 8px; }
.ai-icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.ai-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.ai-messages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-msg { display: flex; }
.ai-msg.user { justify-content: flex-end; }
.ai-msg.assistant { justify-content: flex-start; }
.ai-bubble { max-width: 86%; padding: 10px 12px; border-radius: 10px; font-size: 13px; white-space: pre-wrap; }
.ai-msg.user .ai-bubble { background: var(--primary); color: #fff; }
.ai-msg.assistant .ai-bubble { background: #f4f8ff; color: #1c2c41; }
.ai-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.ai-input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.ai-attachment { margin: 0 12px 8px; padding: 8px 10px; background: #f7faff; border: 1px solid #d4e7ff; border-radius: 8px; font-size: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ai-capture-overlay { position: fixed; inset: 0; background: rgba(15, 26, 45, .86); z-index: 120; display: grid; place-items: center; }
.ai-capture-hint { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); color: #fff; background: rgba(0,0,0,.45); padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.ai-capture-image { max-width: 92vw; max-height: 86vh; object-fit: contain; cursor: crosshair; user-select: none; }
.ai-capture-rect { position: fixed; border: 2px dashed #1890ff; background: rgba(24, 144, 255, .2); pointer-events: none; display: none; }
.row-alert-yellow td { background: #fff8db; }
.row-alert-red td { background: #ffe9e9; }
.warn-pill { color: #a15d00; font-size: 12px; font-weight: 600; }
.inline-editor { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.svor-scroll { overflow-x: auto; }
.table-sticky th:nth-child(-n+4),
.table-sticky td:nth-child(-n+4) { position: sticky; background: #fff; z-index: 1; }
.table-sticky th:nth-child(1), .table-sticky td:nth-child(1) { left: 0; min-width: 56px; }
.table-sticky th:nth-child(2), .table-sticky td:nth-child(2) { left: 56px; min-width: 120px; }
.table-sticky th:nth-child(3), .table-sticky td:nth-child(3) { left: 176px; min-width: 220px; }
.table-sticky th:nth-child(4), .table-sticky td:nth-child(4) { left: 396px; min-width: 120px; }


.table-load-wrap{position:relative;}
.table-load-wrap.is-loading .table{opacity:.45;pointer-events:none;transition:opacity .2s;}
.table-loading-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,.45);z-index:3;}
.table-loading-overlay.hidden{display:none;}
.toast-root{position:fixed;top:16px;right:16px;z-index:1000;display:flex;flex-direction:column;gap:8px;}
.toast{min-width:280px;max-width:420px;background:#fff;border:1px solid var(--line);border-left:4px solid var(--primary);padding:10px 34px 10px 12px;border-radius:10px;position:relative;box-shadow:0 8px 24px rgba(0,0,0,.1);animation:toastIn .2s ease;}
.toast-error{border-left-color:#dc2626;}
.toast-close{position:absolute;top:6px;right:8px;border:0;background:transparent;cursor:pointer;color:#666;}
.toast.fade-out{opacity:0;transform:translateY(-6px);transition:all .3s;}
@keyframes toastIn{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:translateY(0)}}

/* === FMS: File Management System === */
.docs-header { display: flex; justify-content: space-between; align-items: center; }

.fms-tree { background: var(--card-bg,#fff); border: 1px solid var(--line,#e2e8f0);
  border-radius: 12px; padding: 12px; margin-bottom: 16px; max-height: 280px; overflow-y: auto; }
.tree-node { padding: 2px 0; }
.tree-node-row { display: flex; align-items: center; gap: 4px; padding: 3px 6px;
  border-radius: 6px; cursor: pointer; transition: background .15s; }
.tree-node-row:hover { background: var(--accent,#3b82f6); color: #fff; }
.tree-node-row.selected { background: var(--accent,#3b82f6); color: #fff; }
.tree-toggle { width: 16px; text-align: center; user-select: none; font-size: 11px; }
.tree-children { margin-left: 20px; }

.tag-approved { background: #d1fae5; color: #065f46; }
.tag-analyzing { background: #fef3c7; color: #92400e; }
.tag-requires_confirmation { background: #fee2e2; color: #991b1b; }
.tag-archived { background: #f1f5f9; color: #475569; }
.tag-pending { background: #e0e7ff; color: #3730a3; }
.tag-deleted { background: #f1f5f9; color: #94a3b8; }

/* AI Upload / Version Modals */
.ai-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 1000; display: flex; align-items: center; justify-content: center; }
.ai-modal { background: var(--card-bg,#fff); border-radius: 16px; padding: 24px;
  max-width: 520px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.ai-modal h4 { margin: 0 0 12px; font-size: 1.1rem; }
.ai-modal .ai-explanation { background: #f8fafc; border-radius: 8px; padding: 12px;
  margin-bottom: 16px; font-size: .9rem; line-height: 1.5; }
.ai-modal .modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.ai-confidence { font-size: .85rem; color: var(--muted,#64748b); margin-bottom: 8px; }

.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding-right: 22px; }
.dashboard-card.dragging { opacity: .55; outline: 2px dashed var(--primary); }
.widget-list { display: grid; gap: 8px; margin-top: 10px; }
.widget-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: #f8fbff; }
.widget-row small { display: block; color: var(--muted); margin-top: 2px; }
.widget-status { border-radius: 999px; padding: 3px 8px; font-size: 11px; white-space: nowrap; }
.widget-status.ok { background: #e8f7ef; color: #16794a; }
.widget-status.warn { background: #fff7e6; color: #ad6800; }
button[disabled].mini { opacity: .45; cursor: not-allowed; }
.project-switcher { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin-left: auto; }
.project-switcher select { min-width: 220px; max-width: 340px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: #fff; color: var(--text); }
@media (max-width: 760px) { .project-switcher { order: 3; width: 100%; margin-left: 0; } .project-switcher select { flex: 1; min-width: 0; } }
.ai-chat-page .ai-chat-conv {
  width: 100%;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 0;
  text-align: left;
}
.ai-chat-page .ai-chat-conv small {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
@media (max-width: 820px) {
  .ai-chat-page .ai-chat-layout { grid-template-columns: 1fr !important; }
}
