:root {
    color-scheme: light;
    font: 14px/1.55 "Vazirmatn", "IRANSans", "Segoe UI", Tahoma, sans-serif;
    color: #192333;
    background: #f6f8fb;
    --muted: #64758a;
    --line: #d6dfec;
    --accent: #0967ef;
    --accent-dark: #0958bd;
    --connection: #869dbc;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; }
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }
:focus-visible { outline: 3px solid #3686ff; outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(24px, 3vw, 34px); line-height: 1.4; overflow-wrap: anywhere; }
h2 { font-size: 17px; }
.page-head, .section-head, .toolbar-actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.page-head { margin-bottom: 22px; }
.section-head { margin-bottom: 16px; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: 0 1px 3px #2332460b; padding: clamp(14px, 2.1vw, 24px); }
.fields { display: grid; gap: 8px; }
.panel > h2 + .fields { margin-top: 12px; }
.fields label { font-size: 13px; font-weight: 700; }
input, select { inline-size: 100%; min-block-size: 42px; border: 1px solid #afbdd0; border-radius: 8px; background: #fff; color: inherit; padding: 7px 10px; margin-bottom: 5px; }
.button { display: inline-flex; justify-content: center; align-items: center; gap: 6px; padding: 7px 13px; min-height: 39px; border: 1px solid #1571e9; border-radius: 7px; background: linear-gradient(145deg, #217fed, #0965e9); color: white; font-weight: 700; cursor: pointer; text-decoration: none; text-align: center; }
.button:hover { text-decoration: none; background: var(--accent-dark); }
.button-quiet { background: #fff; color: #2a405d; border-color: #cdd9e8; }
.button-quiet:hover { background: #edf3ff; }
.button-small { font-size: 12px; min-height: 33px; padding: 5px 8px; }
.total, .form-hint, .empty-copy { color: var(--muted); font-size: 13px; }
.form-hint { margin-top: 5px; }
.table-scroll { overflow: auto; }
.org-table { width: 100%; text-align: start; border-collapse: collapse; }
.org-table th { background: #eaf1fb; color: #283f60; font-size: 12px; text-align: start; padding: 9px 8px; }
.org-table td { border-bottom: 1px solid var(--line); padding: 11px 8px; overflow-wrap: anywhere; font-size: 13px; }
.org-table tbody tr:last-child td { border-bottom: 0; }
.org-path, .stage { display: block; width: fit-content; font-size: 12px; }
.status { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.status-active { background: #daf3e8; color: #14604a; }
.status-other { background: #f1e9dc; color: #724619; }
.message { padding: 10px 13px; border-radius: 8px; margin-bottom: 14px; }
.error { background: #fce4e9; color: #821f35; }
.success { background: #dff6ee; color: #155c48; }

.chart-editor { scroll-margin-top: 16px; }
.chart-editor select { text-overflow: ellipsis; }
.form-cancel { justify-self: center; font-size: 13px; }
.diagram-panel { padding: 0; }
.chart-toolbar { padding: 14px 16px; margin: 0; border-bottom: 1px solid var(--line); }
.diagram-viewport { overflow: auto; min-height: 380px; max-height: min(72vh, 750px); border-radius: 0 0 10px 10px; background: #f5f8fd radial-gradient(#d3dcec 1px, transparent 1px) 0 0 / 16px 16px; }
.diagram-content { width: max-content; min-width: 100%; padding: 26px; }
.diagram-empty { padding: 52px 20px; text-align: center; background: #f5f8fd; color: var(--muted); border-radius: 0 0 10px 10px; }
.diagram-empty strong { color: #223a58; }
.diagram-empty p { margin-top: 7px; }
.chart-tree { display: flex; justify-content: center; list-style: none; position: relative; padding: 0; margin: 0; }
.chart-tree .chart-tree { padding-top: 20px; }
.chart-tree .chart-tree::before { content: ''; position: absolute; inset-block-start: 0; inset-inline-start: 50%; height: 20px; border-inline-start: 1px solid var(--connection); }
.chart-tree > li { display: flex; align-items: center; flex-direction: column; position: relative; padding: 0 9px; }
.chart-tree .chart-tree > li { padding-top: 20px; }
.chart-tree .chart-tree > li::before, .chart-tree .chart-tree > li::after {
    content: ''; position: absolute; inset-block-start: 0; width: 50%; height: 20px; border-top: 1px solid var(--connection);
}
.chart-tree .chart-tree > li::before { inset-inline-end: 50%; border-inline-end: 1px solid var(--connection); }
.chart-tree .chart-tree > li::after { inset-inline-start: 50%; }
.chart-tree .chart-tree > li:first-child::before, .chart-tree .chart-tree > li:last-child::after { border-top: 0; }
.chart-tree .chart-tree > li:only-child::after { display: none; }
.org-node { position: relative; width: 172px; min-height: 115px; padding: 8px 10px 10px; border: 1px solid #bfcbdd; border-radius: 11px; background: white; box-shadow: 0 3px 10px #17376312; }
.org-node-root { border-block-start: 3px solid var(--accent); }
.org-node-selected { border-color: var(--accent); box-shadow: 0 0 0 2px #ccddff; }
.node-heading { display: flex; align-items: center; justify-content: space-between; min-height: 23px; gap: 4px; font-size: 11px; color: var(--muted); }
.node-heading button { width: 23px; height: 23px; padding: 0; border: 1px solid #aebfd8; border-radius: 5px; color: #214571; background: #edf3ff; cursor: pointer; }
.org-node strong { display: block; overflow-wrap: anywhere; font-size: 14px; }
.node-meta { color: var(--muted); font-size: 11px; }
.node-actions { display: flex; flex-wrap: wrap; gap: 4px 9px; border-top: 1px solid var(--line); padding-top: 5px; margin-top: 7px; font-size: 11px; font-weight: 700; }
@media (max-width: 1150px) {
}
@media (max-width: 650px) {
    
    .diagram-content { width: auto; padding: 14px; }
    .chart-tree, .chart-tree > li { display: block; }
    .chart-tree > li, .chart-tree .chart-tree > li { padding: 6px 0; }
    .chart-tree .chart-tree { padding: 4px 10px 0 0; margin-inline-start: 10px; border-inline-start: 1px solid var(--connection); }
    .chart-tree .chart-tree::before, .chart-tree .chart-tree > li::before, .chart-tree .chart-tree > li::after { display: none; }
    .org-node { max-width: 100%; min-height: 0; }
    .diagram-viewport { min-height: 230px; }
}

:root { --danger: #a42643; --danger-dark: #8d1833; }
.page-head { border-block-end: 1px solid var(--line); padding-block-end: 16px; }
.org-table tbody tr { transition: background-color 160ms ease; }
.org-table tbody tr:hover { background: #f7f9fd; }
.button { transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease; }
.button-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.button-danger:hover { background: var(--danger-dark); }
.button-danger-quiet { color: var(--danger-dark); background: #fff; border-color: #ebcbd3; }
.button-danger-quiet:hover { background: #fff1f4; }
.text-danger { color: var(--danger-dark); }
.org-table td:last-child { white-space: nowrap; }
.archived-organizations { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.archived-organizations summary { color: var(--muted); cursor: pointer; }
.archived-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.diagram-empty .button { margin-top: 14px; }
.org-node { width: 196px; transition: border-color 180ms ease, box-shadow 180ms ease; }
.org-node:hover { box-shadow: 0 5px 16px #17376325; }
.node-heading span { overflow-wrap: anywhere; }
.node-heading button { flex: none; transition: background-color 150ms ease; }
.node-heading button:hover { background: #dce8ff; }

.editor-dialog {
    width: min(460px, calc(100% - 28px));
    max-height: calc(100vh - 28px);
    max-height: calc(100dvh - 28px);
    overflow: auto;
    padding: clamp(16px, 4vw, 25px);
    margin: auto;
    border: 1px solid #d7e3f2;
    border-radius: 17px;
    background: #fff;
    color: inherit;
    box-shadow: 0 22px 72px #10233a4a;
}
.editor-dialog[open] { animation: dialog-enter 210ms ease-out both; }
.editor-dialog::backdrop { background: #101d38a1; animation: backdrop-enter 180ms ease-out both; }
.editor-dialog:modal { position: fixed; }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head { padding-bottom: 10px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { overflow-wrap: anywhere; }
.dialog-actions { justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.dialog-close { display: grid; place-items: center; min-width: 33px; height: 33px; border-radius: 8px; background: #edf2fa; color: #284160; font-size: 21px; }
.dialog-close:hover { text-decoration: none; background: #e0eafb; }
.editor-dialog .form-hint { margin-bottom: 12px; }
@keyframes dialog-enter { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes backdrop-enter { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
    display: inline-block; flex: none; width: 17px; height: 17px;
    fill: none; stroke: currentColor; stroke-width: 1.85;
    stroke-linecap: round; stroke-linejoin: round; vertical-align: middle;
}
.app-shell {
    --sidebar-motion: 480ms cubic-bezier(.3, .08, .22, 1);
    width: calc(100% - 14px); height: calc(100vh - 14px); height: calc(100dvh - 14px);
    max-width: 1800px; margin: 7px auto; display: grid; direction: ltr;
    grid-template-columns: 154px minmax(0, 1fr);
    grid-template-rows: 48px minmax(0, 1fr); border-radius: 15px;
    background: linear-gradient(130deg, #344358 0%, #223145 100%);
    box-shadow: 0 11px 34px rgba(16, 39, 67, .16); overflow: hidden;
}
.topbar, .sidebar, .main-content { direction: rtl; min-width: 0; }
.topbar {
    grid-column: 1 / -1; grid-row: 1; display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.65fr) minmax(0, 1fr);
    align-items: center; gap: 10px; padding: 0 24px; color: #fff;
    background: linear-gradient(180deg, #304258, #233246);
    border-bottom: 1px solid rgba(255,255,255,.12);
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; min-width: 0; }
.brand b { font-size: clamp(12px, 1.15vw, 19px); font-weight: 800; overflow: hidden; text-overflow: ellipsis; }
.brand .icon { width: 24px; height: 24px; }
.page-title { margin: 0; text-align: center; font-size: clamp(14px, 1.25vw, 21px); font-weight: 800; }
.account-box { display: flex; justify-content: flex-end; min-width: 0; }
.account { display: flex; flex-direction: row-reverse; align-items: center; gap: 7px; }
.avatar {
    width: 29px; height: 29px; border-radius: 50%;
    display: grid; place-items: center; background: #8196b1; color: white;
}
.avatar .icon { fill: #fff; stroke-width: 1.2; }
.account-name { font-weight: 750; font-size: 12px; white-space: nowrap; }
.sidebar { grid-column: 1; grid-row: 2; padding: 18px 8px 12px; overflow: auto; background: linear-gradient(125deg, #344458, #253449); }
.side-nav { display: flex; flex-direction: column; gap: 3px; min-height: 100%; }
.side-nav > * { flex-shrink: 0; }
.nav-link {
    position: relative; width: 100%; display: flex; align-items: center; justify-content: flex-start;
    gap: 7px; padding: 7px 8px; min-height: 31px; color: #e7edf6;
    border: 0; border-radius: 8px; background: transparent; text-align: right;
    white-space: nowrap; font-size: 12px; font-weight: 650; cursor: pointer;
}
.nav-label { overflow: hidden; max-inline-size: 13em; }
.nav-link:hover, .nav-link:focus-visible { background-color: #e7f4ff21; text-decoration: none; }
.nav-link.active { background-image: linear-gradient(160deg, #268efc, #0965e9); box-shadow: 0 2px 6px #053d8b36; color: #fff; }
.nav-link.active:hover { filter: brightness(1.14); }
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .nav-link:not(.active, .nav-logout, .sidebar-toggle):hover::after {
    content: "";
    position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
    background-image: linear-gradient(110deg, transparent 42%, #eff9ff10 46%, #eff9ff53 50%, #eff9ff14 54%, transparent 58%);
    background-size: 245% 100%;
    animation: sidebar-hover-shine 500ms cubic-bezier(.52, 0, .48, 1) both;
  }
  @keyframes sidebar-hover-shine {
    from { background-position: right center; }
    to { background-position: left center; }
  }
}
.logout { margin-block-start: auto; padding-block-start: 10px; }
.nav-logout { background-color: #a1283c; color: #ffd4d8; font-weight: 750; }
.nav-logout:hover, .nav-logout:focus-visible { background-color: #b73046; }
.sidebar-toggle { width: 32px; justify-content: center; padding: 5px; }
.sidebar-toggle .icon { transform: rotate(0deg); transform-origin: center; }
.main-content {
    grid-column: 2; grid-row: 2; min-height: 0; padding: clamp(12px, 1.7vw, 26px);
    border-radius: 12px 0 0 0; border-top: 1px solid #dbe2ee; overflow: auto;
    background: radial-gradient(ellipse at 73% -14%, #fff 0, #f0f3f8 70%);
}
@media (min-width: 701px) {
    .app-shell.sidebar-collapsed { grid-template-columns: 54px minmax(0, 1fr); }
    .sidebar-collapsed .sidebar { padding-inline: 6px; }
    .sidebar-collapsed .nav-link { justify-content: center; gap: 0; }
    .sidebar-collapsed .nav-label { max-inline-size: 0; opacity: 0; }
    .sidebar-collapsed .sidebar-toggle .icon { transform: rotate(180deg); }
}
@media (min-width: 701px) and (prefers-reduced-motion: no-preference) {
    .app-shell { transition: grid-template-columns var(--sidebar-motion); }
    .sidebar { transition: padding-inline var(--sidebar-motion); }
    .nav-link { transition: gap var(--sidebar-motion), background-color 160ms ease; }
    .nav-label { transition: max-inline-size var(--sidebar-motion), opacity 240ms ease; }
    .sidebar-toggle .icon { transition: transform var(--sidebar-motion); }
}
@media (max-width: 700px) {
    .app-shell { width: 100%; height: auto; min-height: 100vh; margin: 0; border-radius: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; }
    .topbar { min-height: 64px; grid-template-columns: minmax(0, 1fr) auto; padding: 7px 13px; }
    .brand { grid-row: 1; grid-column: 1; }
    .brand .icon { width: 19px; height: 19px; }
    .page-title { grid-row: 2; grid-column: 1; text-align: start; }
    .account-box { grid-row: 1 / span 2; grid-column: 2; }
    .sidebar { grid-row: 2; padding: 7px; }
    .side-nav { flex-direction: row; flex-wrap: wrap; align-items: center; }
    .sidebar-toggle { display: none; }
    .logout { margin: 0; margin-inline-start: auto; padding: 0; }
    .nav-link { min-height: 35px; }
    .main-content { grid-column: 1; grid-row: 3; border-radius: 0; overflow: visible; }
}

.node-actions button {
    border: 0; background: none; color: var(--accent-dark); font: inherit; padding: 2px 0; cursor: pointer;
}
.node-actions button:hover { text-decoration: underline; }
.node-actions button.text-danger { color: var(--danger-dark); }
.dialog-close { border: 0; cursor: pointer; }
.button:disabled, .nav-link:disabled { opacity: .65; cursor: wait; }

.chart-organization-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 265px), 1fr));
    gap: 16px;
}
.chart-organization-card {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-content: space-between;
    align-items: start;
    gap: 16px 13px;
    min-height: 148px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: inherit;
    box-shadow: 0 2px 7px #2332460c;
    transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}
.chart-organization-card:hover {
    border-color: #8fb8f4;
    background: #fbfdff;
    box-shadow: 0 5px 16px #23324618;
    text-decoration: none;
}
.chart-card-icon {
    display: grid; place-items: center; width: 48px; height: 48px;
    border-radius: 10px; background: #e4efff; color: var(--accent-dark);
}
.chart-card-icon .icon { width: 24px; height: 24px; }
.chart-card-body { min-width: 0; align-self: center; display: grid; gap: 3px; overflow-wrap: anywhere; }
.chart-card-body strong { font-size: 16px; }
.chart-card-body [data-card-code] { justify-self: start; color: var(--muted); font: 12px/1.4 monospace; }
.chart-card-action { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 10px; color: var(--accent-dark); font-weight: 700; }
.chart-card-action span { margin-inline-start: 5px; }

.org-node[data-unit] { cursor: grab; }
.node-controls { flex: none; display: inline-flex; align-items: center; gap: 5px; }
.node-grip { font: 700 21px/1 system-ui, sans-serif; color: #617a99; touch-action: none; user-select: none; cursor: grab; }
.chart-is-dragging, .chart-is-dragging .org-node[data-unit] { cursor: grabbing; user-select: none; }
.chart-is-dragging .chart-drag-source { opacity: .32; }
.chart-drop-gap { position: absolute; display: none; inset-block: -2px; width: 12px; z-index: 2; border-radius: 6px; }
.chart-drop-before { inset-inline-start: -13px; }
.chart-drop-after { inset-inline-end: -13px; }
.chart-is-dragging .chart-drop-gap { display: block; }
.chart-drop-gap.chart-drop-target { background: var(--accent); box-shadow: 0 0 0 3px #d6e6ff; }
.org-node.chart-drop-target { outline: 2px solid var(--accent); outline-offset: 2px; background: #edf5ff; }
.chart-drag-ghost {
    position: fixed; inset: 0 auto auto 0; margin: 0; z-index: 1000; direction: rtl;
    pointer-events: none; opacity: .86; box-shadow: 0 8px 24px #1b375e40;
}
@media (max-width: 650px) {
    .chart-drop-gap { inset-inline: 0; width: auto; height: 10px; }
    .chart-drop-before { inset-block: -11px auto; }
    .chart-drop-after { inset-block: auto -11px; }
}
