:root { --bg: #0d1117; --bg1: #161b22; --bg2: #1c2333; --border: #30363d; --text: #e6edf3; --muted: #7d8590; --blue: #58a6ff; --green: #3fb950; --red: #f85149; --purple: #bc8cff; --yellow: #d29922; --orange: #f0883e; }
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--text); font-family: 'Noto Sans Thai', -apple-system, sans-serif; overflow: hidden; height: 100vh; }
[x-cloak] { display: none !important; }
input, select, textarea { padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 13px; width: 100%; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); }
button { padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg1); color: var(--text); font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; }
button:hover { border-color: var(--blue); }
button:disabled { opacity: .5; cursor: wait; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-xs { padding: 2px 6px; font-size: 10px; border: none; background: none; color: var(--muted); cursor: pointer; }
.btn-xs:hover { color: var(--text); }
.btn-danger { color: var(--red); }
.btn-file { padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg1); color: var(--text); font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; }
.muted { color: var(--muted); font-size: 11px; }
.empty-msg { font-size: 12px; color: var(--muted); padding: 16px; text-align: center; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 600; color: var(--muted); flex: 1; }
h3 { font-size: 15px; font-weight: 700; }

/* ─── AUTH PAGE ─── */
.auth-page { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--bg); }
.auth-card { background: var(--bg1); border: 1px solid var(--border); border-radius: 16px; padding: 40px 36px; width: 400px; max-width: 95vw; }
.auth-logo { font-size: 28px; font-weight: 800; text-align: center; margin-bottom: 4px; }
.auth-sub { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 28px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-btn { width: 100%; padding: 10px; font-size: 14px; margin-top: 4px; }
.auth-error { color: var(--red); font-size: 12px; padding: 8px 12px; background: rgba(248,81,73,.1); border-radius: 6px; }
.auth-switch { text-align: center; font-size: 12px; color: var(--muted); margin-top: 16px; }
.auth-switch a { color: var(--blue); text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }

/* ─── User Menu ─── */
.user-avatar-btn { width: 32px; height: 32px; border-radius: 50%; background: var(--purple); color: #fff; border: none; font-size: 14px; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.user-avatar-btn:hover { opacity: .85; border-color: transparent; }
.user-dropdown { position: absolute; right: 0; top: 40px; background: var(--bg1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 200px; z-index: 300; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.user-dropdown__name { font-size: 14px; font-weight: 700; }
.user-dropdown__email { font-size: 11px; color: var(--muted); margin-top: 2px; }
.user-dropdown__role { font-size: 10px; color: var(--purple); font-weight: 600; text-transform: uppercase; margin-top: 4px; }
.user-dropdown__item { width: 100%; text-align: left; padding: 6px 0; border: none; background: none; color: var(--text); font-size: 13px; cursor: pointer; font-family: inherit; }
.user-dropdown__item:hover { color: var(--red); border-color: transparent; }

/* ─── Home Tabs ─── */
.home-tabs { display: flex; gap: 0; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.home-tab { padding: 8px 20px; font-size: 13px; font-weight: 600; color: var(--muted); border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; border-radius: 0; font-family: inherit; }
.home-tab:hover { color: var(--text); border-color: transparent; }
.home-tab--active { color: var(--blue); border-bottom-color: var(--blue); }

/* ─── Users Table ─── */
.users-table-wrap { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th { text-align: left; padding: 10px 12px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; border-bottom: 1px solid var(--border); }
.users-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.users-table tr:hover td { background: rgba(88,166,255,.04); }
.role-badge { font-size: 10px; padding: 2px 8px; border-radius: 10px; background: rgba(125,133,144,.15); color: var(--muted); font-weight: 600; text-transform: uppercase; }
.role-badge--admin { background: rgba(188,140,255,.15); color: var(--purple); }
.status-active { color: var(--green); font-size: 12px; font-weight: 600; }
.status-inactive { color: var(--red); font-size: 12px; font-weight: 600; }
.actions-cell { display: flex; gap: 4px; }

/* ─── HOME ─── */
.home { padding: 40px; max-width: 1100px; margin: 0 auto; height: 100vh; overflow-y: auto; }
.home__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.home__title { font-size: 28px; font-weight: 800; }
.home__sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.home__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.pcard { background: var(--bg1); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; cursor: pointer; transition: all .2s; }
.pcard:hover { border-color: var(--blue); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.pcard--empty { border-style: dashed; }
.pcard__preview { height: 110px; background: var(--bg2); padding: 8px; overflow: hidden; }
.pcard__body { padding: 12px 14px 6px; }
.pcard__name { font-size: 14px; font-weight: 700; }
.pcard__meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.pcard__foot { padding: 6px 14px 12px; }

/* ─── PROJECT SHELL ─── */
.project-shell { display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 6px 16px; background: var(--bg1); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.topbar__back { border: none; background: none; color: var(--blue); font-size: 13px; font-weight: 700; cursor: pointer; padding: 4px 8px; }
.topbar__title { font-size: 14px; font-weight: 700; flex: 1; }
.topbar__actions { display: flex; gap: 8px; }

/* Layer Tabs */
.layer-tabs { display: flex; background: var(--bg1); border-bottom: 1px solid var(--border); padding: 0 12px; flex-shrink: 0; }
.ltab { display: flex; align-items: center; gap: 5px; padding: 8px 14px; font-size: 12px; font-weight: 600; color: var(--muted); border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; border-radius: 0; }
.ltab:hover { color: var(--text); border-color: transparent; }
.ltab--active { color: var(--text); }

/* Tab Body */
.tab-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* Scroll pages (Strategy, Business, Roadmap) */
.page-scroll { flex: 1; overflow-y: auto; padding: 20px 24px; }
.page-head { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 800; margin-bottom: 20px; padding: 12px 16px; background: var(--bg1); border: 1px solid var(--border); border-radius: 10px; border-left-width: 4px; }

/* ─── DIAGRAM FULL ─── */
.diagram-full { flex: 1; display: flex; overflow: hidden; position: relative; }
.dg-sidebar { width: 0; overflow: hidden; transition: width .2s ease; background: var(--bg1); border-right: 1px solid var(--border); flex-shrink: 0; }
.dg-sidebar--open { width: 240px; overflow-y: auto; }
.dg-sidebar__head { padding: 10px 12px; font-size: 13px; font-weight: 700; background: var(--bg2); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.dg-sidebar__section { border-bottom: 1px solid var(--border); }
.dg-sidebar__label { padding: 8px 12px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; display: flex; align-items: center; justify-content: space-between; }
.dg-el { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--border); cursor: grab; font-size: 12px; }
.dg-el:hover { background: rgba(88,166,255,.04); }
.dg-el__type { padding: 1px 5px; border-radius: 3px; font-size: 9px; font-weight: 700; white-space: nowrap; flex-shrink: 0; }
.dg-el__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dg-rel { display: flex; align-items: center; gap: 4px; padding: 5px 12px; border-bottom: 1px solid var(--border); font-size: 11px; }
.dg-rel span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-toggle { position: absolute; left: 0; top: 50%; transform: translateY(-50%); z-index: 10; width: 20px; height: 48px; border-radius: 0 6px 6px 0; border: 1px solid var(--border); border-left: none; background: var(--bg1); color: var(--muted); font-size: 10px; cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; transition: left .2s; }
.dg-sidebar--open ~ .sidebar-toggle { left: 240px; }

.dg-canvas { flex: 1; position: relative; overflow: auto; background: var(--bg); background-image: radial-gradient(circle, var(--border) 1px, transparent 1px); background-size: 20px 20px; }

/* Detail Panel */
.detail-panel { position: absolute; right: 0; top: 0; width: 280px; height: 100%; background: var(--bg1); border-left: 1px solid var(--border); z-index: 20; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.detail-panel__close { position: absolute; top: 8px; right: 8px; border: none; background: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.detail-panel h3 { font-size: 16px; font-weight: 800; padding-right: 20px; }
.detail-panel__type { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 6px; display: inline-block; }
.detail-panel__doc { font-size: 12px; color: var(--muted); line-height: 1.6; }
.detail-panel__rels { font-size: 12px; }
.detail-panel__rel { display: flex; align-items: center; gap: 4px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.detail-panel__rel-arrow { color: var(--blue); font-weight: 700; }

/* ─── Nodes ─── */
.d-node { position: absolute; border-radius: 8px; border: 1px solid var(--border); background: var(--bg1); cursor: move; display: flex; align-items: center; gap: 8px; padding: 0 10px; z-index: 2; user-select: none; }
.d-node:hover { box-shadow: 0 0 0 2px var(--blue); }
.d-node__icon { font-size: 10px; flex-shrink: 0; width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-weight: 700; text-transform: uppercase; }
.d-node__info { flex: 1; overflow: hidden; }
.d-node__label { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-node__type { font-size: 9px; color: var(--muted); }
.d-node__del { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; background: var(--red); border: none; color: #fff; font-size: 12px; cursor: pointer; display: none; padding: 0; line-height: 18px; text-align: center; }
/* BPMN Shapes */
.d-node--circle { border-radius: 50%; width: 50px !important; height: 50px !important; justify-content: center; padding: 0; }
.d-node--circle .d-node__icon { display: none; }
.d-node--circle .d-node__info { text-align: center; }
.d-node--circle .d-node__label { font-size: 8px; }
.d-node--circle .d-node__type { display: none; }
.d-node--diamond { border-radius: 4px; transform: rotate(45deg); width: 50px !important; height: 50px !important; justify-content: center; padding: 0; }
.d-node--diamond .d-node__inner { transform: rotate(-45deg); text-align: center; }
.d-node--diamond .d-node__icon { display: none; }
.d-node--diamond .d-node__label { font-size: 7px; }
.d-node--diamond .d-node__type { display: none; }
.d-node--diamond .d-node__connect { bottom: -10px; right: -2px; }
.d-node--diamond .d-node__del { top: -10px; right: -2px; }

/* ─── Swim Lanes ─── */
.d-lane { position: absolute; border-radius: 12px; border: 2px solid; background: rgba(255,255,255,.03); z-index: 0; cursor: move; user-select: none; min-width: 200px; min-height: 100px; pointer-events: auto; display: flex; flex-direction: column; }
.edge-wrap { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
.edge-wrap svg { pointer-events: none; }
.edge-wrap svg .edge-group { pointer-events: auto; }
.d-lane:hover { box-shadow: 0 0 0 3px rgba(88,166,255,.35); z-index: 3; border-width: 3px; }
.d-lane__header { padding: 6px 10px; }
.d-lane__type { font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px; display: inline-block; }
.d-lane__name { font-size: 13px; font-weight: 600; padding: 6px 14px; margin-top: auto; color: var(--text); opacity: .7; }
.d-lane__body { flex: 1; }
.d-lane:hover .d-node__del { display: block; }

/* Edge hover */
.edge-group:hover .edge-line { stroke-width: 3 !important; filter: drop-shadow(0 0 3px rgba(88,166,255,.5)); }
.edge-group:hover .edge-label { fill: #e6edf3 !important; font-weight: 600; }
.edge-group:hover .edge-del-bg { opacity: 1 !important; cursor: pointer; pointer-events: all; }
.edge-group:hover .edge-del-text { opacity: 1 !important; cursor: pointer; pointer-events: all; }

.d-node__connect { position: absolute; bottom: -6px; right: 14px; width: 18px; height: 18px; border-radius: 50%; background: var(--blue); border: 2px solid var(--bg1); color: #fff; font-size: 10px; cursor: crosshair; display: none; padding: 0; line-height: 14px; text-align: center; z-index: 3; }
.d-node:hover .d-node__connect { display: block; }
.d-node:hover .d-node__del { display: block; }
.d-node.connectable { cursor: crosshair; }
.d-node.connectable:hover { box-shadow: 0 0 0 2px var(--green); }
.connect-preview { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 12px; background: var(--bg2); border-radius: 8px; }
.connect-node-label { font-size: 13px; font-weight: 700; padding: 4px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
.connect-arrow { color: var(--blue); font-size: 18px; font-weight: 700; }

/* ─── Business Page ─── */
.biz-page { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.sub-tabs { display: flex; gap: 0; padding: 0 16px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sub-tab { padding: 8px 16px; font-size: 12px; font-weight: 600; color: var(--muted); border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; border-radius: 0; }
.sub-tab:hover { color: var(--text); border-color: transparent; }
.sub-tab--active { color: var(--blue); border-bottom-color: var(--blue); }
.d-node--diamond { border-radius: 2px; transform: rotate(0deg); }
.d-node--vs { border-radius: 12px; }

/* ─── Shared ─── */
.sec-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.hover-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
*:hover > .hover-actions { opacity: 1; }

/* Strategy */
.strat-section { margin-bottom: 20px; }
.vision-card { background: linear-gradient(135deg, rgba(245,158,11,.1), rgba(245,158,11,.02)); border: 1px solid rgba(245,158,11,.3); border-radius: 12px; padding: 20px; position: relative; margin-bottom: 16px; }
.vision-card__name { font-size: 18px; font-weight: 800; margin-bottom: 6px; }
.vision-card__doc { font-size: 13px; color: var(--muted); line-height: 1.6; }
.scard { background: var(--bg1); border: 1px solid var(--border); border-radius: 10px; padding: 14px; position: relative; }
.scard__icon { font-size: 20px; margin-bottom: 6px; }
.scard__name { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.scard__doc { font-size: 11px; color: var(--muted); line-height: 1.5; }
.scard--goal { border-left: 3px solid #f59e0b; }
.scard--kpi { border-left: 3px solid #06b6d4; }
.scard--gap { border-left: 3px solid var(--red); background: rgba(248,81,73,.05); }
.scard--milestone { border-left: 3px solid var(--green); }
.list-item { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--bg1); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; font-size: 13px; position: relative; }

/* Business */
.bcard { background: var(--bg1); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 8px; position: relative; }
.bcard--cap { border-left: 3px solid #3b82f6; }
.bcard--proc { display: flex; align-items: center; gap: 10px; }
.bcard--role { display: flex; align-items: center; gap: 10px; }
.bcard__icon { font-size: 20px; flex-shrink: 0; }
.bcard__name { font-size: 13px; font-weight: 700; }
.bcard__doc { font-size: 11px; color: var(--muted); }
.bcard__avatar { width: 36px; height: 36px; border-radius: 50%; background: rgba(59,130,246,.15); color: var(--blue); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }

/* Roadmap */
.timeline { position: relative; padding-left: 30px; margin-bottom: 24px; }
.timeline::before { content: ''; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline__item { display: flex; gap: 16px; margin-bottom: 16px; position: relative; }
.timeline__marker { width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; position: absolute; left: -30px; top: 4px; border: 3px solid var(--bg); }
.timeline__content { background: var(--bg1); border: 1px solid var(--border); border-radius: 10px; padding: 16px; flex: 1; position: relative; }
.timeline__name { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.timeline__doc { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 200; backdrop-filter: blur(4px); }
.modal { background: var(--bg1); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 480px; max-width: 95vw; display: flex; flex-direction: column; gap: 12px; }
.modal h3 { font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ─── Toast ─── */
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; }
.toast { padding: 10px 24px; border-radius: 8px; font-size: 13px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: toastIn .25s ease; }
.toast--ok { background: rgba(34,197,94,.15); border: 1px solid rgba(34,197,94,.3); color: #22c55e; }
.toast--del { background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.3); color: #ef4444; }
@keyframes toastIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }

@media (max-width: 768px) {
  .two-col, .three-col { grid-template-columns: 1fr; }
  .ltab span:last-child { display: none; }
}
