/* ============================================================
   Agency (v2) — theme + layout khởi tạo. Dark, thương hiệu PinkAGC (hồng), điểm nhấn vàng nhẹ.
   Chỉ là KHUNG: đủ để duyệt bố cục, chưa phải bản hoàn thiện.
   ============================================================ */
:root {
  --bg:            #0f0d12;
  --bg-panel:      #171319;
  --bg-elev:       #1e1922;
  --bg-hover:      #241d29;
  --border:        #2c2530;
  --text:          #efe9f2;
  --text-dim:      #a99fb2;
  --text-mute:     #6f6577;
  --accent:        #ff4f9a;   /* hồng PinkAGC */
  --accent-soft:   rgba(255,79,154,0.14);
  --accent-border: rgba(255,79,154,0.42);
  --gold:          #e8c07a;   /* điểm nhấn vàng nhẹ kiểu premium */
  --ok:            #34d399;
  --warn:          #fbbf24;
  --danger:        #f26d6d;
  --radius:        10px;
  font-family: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
button, input, select, textarea { font-family: inherit; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 13px; }

#ag-app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ---------- Header ---------- */
.ag-header {
  height: 54px; flex: 0 0 54px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(180deg, #1b1620, #141018);
  border-bottom: 1px solid var(--border);
}
.ag-brand { display: flex; align-items: center; gap: 9px; }
.ag-logo-img { width: 30px; height: 30px; border-radius: 8px; display: block; object-fit: contain; background: #fff; }
.ag-name { font-size: 17px; font-weight: 800; letter-spacing: .2px; }
.ag-name b { color: var(--accent); }
.ag-tagline {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  color: var(--gold); border: 1px solid rgba(232,192,122,.4); padding: 2px 7px; border-radius: 20px;
}
.ag-ver { font-size: 11px; color: var(--text-mute); }
.ag-header-right { display: flex; align-items: center; gap: 12px; }
.ag-badge { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 20px; }
.ag-badge-warn { color: var(--warn); background: rgba(251,191,36,.12); border: 1px solid rgba(251,191,36,.35); }
.ag-badge-ok   { color: var(--ok);   background: rgba(52,211,153,.12); border: 1px solid rgba(52,211,153,.35); }
.ag-badge-plan { color: var(--gold); background: rgba(232,192,122,.1);  border: 1px solid rgba(232,192,122,.3); }
.ag-user { font-size: 12px; color: var(--text-dim); }

/* ---------- Body 3 cột ---------- */
.ag-body { flex: 1 1 auto; display: grid; grid-template-columns: 54px 1fr 340px; min-height: 0; }
.ag-body.has-pipeline { grid-template-columns: 54px 1fr 300px 340px; }

/* Rail icon trái */
.ag-rail {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0;
  background: var(--bg-panel); border-right: 1px solid var(--border);
}
.ag-rail-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 0; cursor: pointer;
  background: transparent; color: var(--text-dim); font-size: 17px; transition: .15s;
}
.ag-rail-btn:hover { background: var(--bg-hover); color: var(--text); }
.ag-rail-btn.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- Trung tâm ---------- */
.ag-main { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.ag-tabs { display: flex; gap: 6px; padding: 12px 16px 0; }
.ag-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--border); border-bottom: 0;
  border-radius: 10px 10px 0 0; background: var(--bg-panel);
  color: var(--text-dim); font-size: 13px; font-weight: 600; cursor: pointer; transition: .15s;
}
.ag-tab:hover { color: var(--text); }
.ag-tab.active { background: var(--bg-elev); color: var(--accent); border-color: var(--accent-border); }
.ag-count {
  font-size: 11px; font-weight: 700; min-width: 18px; text-align: center;
  padding: 1px 6px; border-radius: 20px; background: rgba(255,255,255,.06); color: var(--text-dim);
}
.ag-tab.active .ag-count { background: var(--accent-soft); color: var(--accent); }

.ag-toolbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--bg-elev); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.ag-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-panel); color: var(--text); font-size: 12.5px; font-weight: 600; cursor: pointer; transition: .15s;
}
.ag-btn:hover { background: var(--bg-hover); border-color: var(--text-mute); }
.ag-btn-primary { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.ag-btn.ag-icon { padding: 8px 10px; }
.ag-search-wrap { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px; }
.ag-search-ic { color: var(--text-mute); font-size: 12px; }
.ag-search { flex: 1; background: transparent; border: 0; outline: 0; color: var(--text); font-size: 13px; padding: 8px 0; }
.ag-search::placeholder { color: var(--text-mute); }

.ag-table-wrap { flex: 1 1 auto; overflow: auto; min-height: 0; }
.ag-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ag-table thead th {
  position: sticky; top: 0; z-index: 1; text-align: left; font-weight: 700; color: var(--text-dim);
  padding: 11px 14px; background: var(--bg-panel); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.ag-table tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.ag-table tbody tr:hover { background: var(--bg-hover); }
.ag-col-cb { width: 40px; }
.ag-empty td { text-align: center; color: var(--text-mute); padding: 40px 14px; }

.ag-footer {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--bg-panel); border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim);
}
.ag-footer b { color: var(--text); }
.ag-sep { color: var(--text-mute); }

/* ---------- Workflow phải ---------- */
.ag-workflow { display: flex; flex-direction: column; background: var(--bg-panel); border-left: 1px solid var(--border); min-height: 0; }
.ag-wf-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--border); }
.ag-wf-title { display: block; font-size: 13px; font-weight: 800; color: var(--gold); margin-bottom: 10px; }
.ag-wf-search { width: 100%; padding: 8px 12px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 12.5px; outline: 0; }
.ag-wf-search::placeholder { color: var(--text-mute); }
.ag-wf-body { flex: 1 1 auto; overflow: auto; padding: 10px; min-height: 0; }

.ag-wf-group { margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.ag-wf-group-head {
  display: flex; align-items: center; justify-content: space-between; cursor: pointer;
  padding: 10px 12px; background: var(--bg-elev); font-size: 12.5px; font-weight: 700;
}
.ag-wf-group-head .ag-dot { color: var(--accent); margin-right: 7px; }
.ag-wf-group-count { font-size: 11px; font-weight: 700; color: var(--text-mute); }
.ag-wf-item {
  display: flex; align-items: center; gap: 9px; padding: 10px 12px;
  border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-dim); cursor: pointer; transition: .15s;
}
.ag-wf-item:hover { background: var(--bg-hover); color: var(--text); }
.ag-wf-item .ag-wf-ico { width: 16px; text-align: center; opacity: .85; }
.ag-wf-item .ag-wf-toggle { width: 34px; height: 18px; border-radius: 20px;
  background: var(--border); position: relative; flex: 0 0 auto; transition: .15s; }
.ag-wf-item.on .ag-wf-toggle { background: var(--accent); }
.ag-wf-item .ag-wf-toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; transition: .15s; }
.ag-wf-item.on .ag-wf-toggle::after { left: 18px; }

/* Workflow — nhóm gập được + handle + chevron + info */
.ag-wf-group-head { user-select: none; }
.ag-wf-group-name { display: inline-flex; align-items: center; }
.ag-wf-group-right { display: inline-flex; align-items: center; gap: 8px; }
.ag-wf-chevron { color: var(--text-mute); font-size: 10px; transition: transform .15s; }
.ag-wf-group.collapsed .ag-wf-items { display: none; }
.ag-wf-group.collapsed .ag-wf-chevron { transform: rotate(180deg); }
.ag-wf-handle { color: var(--text-mute); cursor: grab; font-size: 12px; opacity: .7; }
.ag-wf-name { flex: 1; }
.ag-wf-info { color: var(--text-mute); font-size: 12px; opacity: .8; }
.ag-wf-info:hover { color: var(--accent); }
.ag-wf-none { padding: 20px; color: var(--text-mute); text-align: center; }

.ag-wf-actions { flex: 0 0 auto; display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.ag-btn-go { flex: 1; justify-content: center; background: var(--ok); color: #06281c; border-color: transparent; font-weight: 800; }
.ag-btn-stop { flex: 1; justify-content: center; background: var(--danger); color: #2a0d0d; border-color: transparent; font-weight: 800; }

/* Trạng thái tính năng đã thêm vào quy trình (panel giữa) */
.ag-wf-add { width: 20px; height: 20px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); color: var(--text-mute); font-size: 13px; flex: 0 0 auto; }
.ag-wf-add::before { content: "+"; }
.ag-wf-item:hover .ag-wf-add { border-color: var(--accent-border); color: var(--accent); }
.ag-wf-item.added { opacity: .6; }
.ag-wf-item.added .ag-wf-add { border-color: transparent; color: var(--ok); background: rgba(52,211,153,.12); }
.ag-wf-item.added .ag-wf-add::before { content: "✓"; }

/* ---------- Panel Quy trình (pipeline) ---------- */
.ag-pipeline { display: none; flex-direction: column; background: var(--bg); border-left: 1px solid var(--border); min-height: 0; }
.ag-body.has-pipeline .ag-pipeline { display: flex; }
.ag-pl-head { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--border); }
.ag-pl-title { font-size: 13px; font-weight: 800; }
.ag-pl-count { font-size: 12px; font-weight: 600; color: var(--text-mute); }
.ag-pl-body { flex: 1 1 auto; overflow: auto; padding: 12px; min-height: 0; }
.ag-pl-empty { padding: 30px 14px; color: var(--text-mute); text-align: center; font-size: 12.5px; }

.ag-pl-step { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; background: var(--bg-panel); overflow: hidden; }
.ag-pl-step-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--bg-elev); }
.ag-pl-badge { font-size: 11px; font-weight: 700; color: var(--gold); border: 1px solid rgba(232,192,122,.35); padding: 2px 8px; border-radius: 20px; }
.ag-pl-step-name { flex: 1; font-size: 12.5px; font-weight: 600; }
.ag-pl-remove { color: var(--text-mute); cursor: pointer; font-size: 13px; }
.ag-pl-remove:hover { color: var(--danger); }
.ag-pl-step-body { padding: 10px 12px; }
.ag-pl-lbl { font-size: 11px; color: var(--text-dim); margin: 6px 0 4px; }
.ag-pl-select, .ag-pl-input { width: 100%; padding: 8px 10px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 12.5px; outline: 0; }
.ag-pl-select:focus, .ag-pl-input:focus { border-color: var(--accent-border); }
.ag-pl-section { font-size: 12px; font-weight: 700; color: var(--gold); margin: 12px 0 6px; padding: 7px 10px; border: 1px solid rgba(232,192,122,.3); border-radius: 8px; background: rgba(232,192,122,.06); }
.ag-pl-radio { display: flex; gap: 18px; padding: 4px 0 2px; }
.ag-pl-radio label { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.ag-pl-radio input { width: auto; }
.ag-pl-textarea { min-height: 84px; resize: vertical; font-family: inherit; line-height: 1.5; }
.ag-pl-check { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim); margin: 8px 0 4px; cursor: pointer; }
.ag-pl-check input { width: auto; }

.ag-pl-foot { flex: 0 0 auto; padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.ag-pl-row { display: flex; gap: 8px; }
.ag-pl-field { flex: 1; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim);
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.ag-pl-field input { flex: 1; width: 100%; background: transparent; border: 0; outline: 0; color: var(--text); font-size: 13px; text-align: right; }
.ag-pl-foot .ag-btn-go { flex: 1; justify-content: center; background: var(--ok); color: #06281c; border-color: transparent; font-weight: 800; }
.ag-pl-foot .ag-btn-stop { flex: 1; justify-content: center; background: var(--danger); color: #2a0d0d; border-color: transparent; font-weight: 800; }
.ag-pl-foot #ag-save-tpl { flex: 1; justify-content: center; }

/* Dấu tính năng đã đấu dây + ô tiến trình bảng */
.ag-wired { color: var(--ok); font-size: 9px; vertical-align: middle; }
.ag-proc { font-weight: 600; font-size: 12px; color: var(--text-dim); }

/* Responsive: thu gọn khi màn hẹp (webapp thiết kế cho màn rộng như SMIT) */
@media (max-width: 1400px) { .ag-body.has-pipeline { grid-template-columns: 54px 1fr 270px 310px; } }
@media (max-width: 1150px) { .ag-body, .ag-body.has-pipeline { grid-template-columns: 54px 1fr 340px; } .ag-body.has-pipeline .ag-pipeline { display: none; } }
@media (max-width: 950px)  { .ag-body, .ag-body.has-pipeline { grid-template-columns: 1fr; } .ag-rail, .ag-workflow, .ag-pipeline { display: none !important; } }
