:root {
    --navy: #173452;
    --navy-deep: #0c2137;
    --navy-soft: #284b70;
    --surface: #ffffff;
    --canvas: #f3f6f9;
    --line: #e5eaf0;
    --text: #17243a;
    --muted: #758198;
    --primary: #3b82f6;
    --success: #22a56b;
    --warning: #e9a008;
    --danger: #d9485f;
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius: 14px;
    --shadow: 0 7px 25px rgba(25, 45, 74, .07);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--canvas); font-size: 14px; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, .button { border: 0; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(59,130,246,.28); outline-offset: 2px; }

.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; width: var(--sidebar-width); color: #dbe8f5; background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%); display: flex; flex-direction: column; transition: width .22s ease, transform .22s ease; box-shadow: 10px 0 35px rgba(7,23,39,.11); }
.sidebar-logo { min-height: var(--header-height); border-bottom: 1px solid rgba(255,255,255,.09); display: flex; align-items: center; padding: 0 19px; }
.sidebar-logo a, .login-brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 35px; height: 35px; flex: 0 0 35px; display: block; object-fit: contain; }
.brand-copy { min-width: 0; display: grid; line-height: 1.05; white-space: nowrap; }
.brand-copy strong { color: #fff; font-size: 17px; letter-spacing: .2px; }
.brand-copy small { color: #a9bfd3; font-size: 10px; margin-top: 5px; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-menu { flex: 1; padding: 13px 10px; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
.menu-link, .menu-group-toggle, .menu-editor-link { min-height: 42px; width: 100%; color: #bbcbda; border-radius: 10px; display: flex; align-items: center; gap: 11px; padding: 0 12px; transition: .18s ease; background: transparent; white-space: nowrap; }
.menu-link:hover, .menu-group-toggle:hover, .menu-editor-link:hover { color: #fff; background: rgba(255,255,255,.075); }
.menu-link.active { color: #fff; background: linear-gradient(90deg, rgba(73,113,255,.38), rgba(45,211,192,.13)); box-shadow: inset 3px 0 #6ca1ff; }
.menu-link i, .menu-group-toggle i, .menu-editor-link i { font-size: 20px; flex: 0 0 20px; }
.menu-link span, .menu-editor-link span { overflow: hidden; text-overflow: ellipsis; }
.menu-group { margin: 4px 0; }
.menu-group-toggle { justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.menu-group-toggle span { display: flex; align-items: center; gap: 11px; }
.menu-group-toggle > i { transition: transform .18s ease; }
.menu-group.expanded .menu-group-toggle > i { transform: rotate(180deg); }
.menu-group-items { display: none; padding: 2px 0 4px 11px; }
.menu-group.expanded .menu-group-items { display: block; }
.menu-group-items .menu-link { min-height: 38px; font-size: 13px; }
.menu-editor-link { margin: 8px 10px 12px; width: calc(100% - 20px); border-top: 1px solid rgba(255,255,255,.08); border-radius: 0; padding-top: 11px; }

.admin-header { position: fixed; top: 0; right: 0; left: var(--sidebar-width); z-index: 40; height: var(--header-height); padding: 0 24px; background: rgba(255,255,255,.96); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; transition: left .22s ease; }
.header-start, .header-right { display: flex; align-items: center; gap: 9px; }
.sidebar-toggle, .logout { width: 38px; height: 38px; border-radius: 9px; background: transparent; color: #607089; display: grid; place-items: center; }
.sidebar-toggle:hover, .logout:hover { background: #eef3f8; color: var(--navy); }
.sidebar-toggle i, .logout i { font-size: 23px; }
.global-search { width: min(410px, 34vw); height: 40px; background: #f3f6fa; border: 1px solid transparent; border-radius: 10px; display: flex; align-items: center; gap: 8px; padding: 0 12px; position: relative; }
.global-search:focus-within { border-color: #a9c9ff; background: white; }
.global-search i { font-size: 19px; color: #8592a5; }
.global-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.search-results { position: fixed; z-index: 90; width: min(410px, calc(100vw - 32px)); max-height: 370px; overflow: auto; padding: 7px; background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 18px 45px rgba(20,40,67,.18); }
.search-results a { display: grid; gap: 2px; padding: 10px 11px; border-radius: 8px; }
.search-results a:hover { background: #f2f6fb; }
.search-results b { font-size: 13px; }
.search-results span { color: var(--muted); font-size: 12px; }
.search-results em { color: var(--primary); font-size: 10px; font-style: normal; text-transform: uppercase; letter-spacing: .05em; }
.header-action { height: 38px; padding: 0 12px; color: #52627a; background: transparent; border-radius: 9px; display: inline-flex; align-items: center; gap: 7px; }
.header-action:hover { color: var(--navy); background: #edf3f9; }
.header-action i { font-size: 19px; }
.header-user { display: flex; align-items: center; gap: 8px; padding: 0 8px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; background: linear-gradient(135deg, #7658ef, #36b8d6); }

.main-content { min-height: 100vh; padding: calc(var(--header-height) + 25px) 25px 35px calc(var(--sidebar-width) + 25px); transition: padding-left .22s ease; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-heading h1 { margin: 0 0 4px; font-size: clamp(22px, 2vw, 28px); letter-spacing: -.03em; }
.page-heading p, .page-heading time { margin: 0; color: var(--muted); }
.page-heading time { font-size: 12px; }

.sidebar-collapsed { --sidebar-width: 74px; }
.sidebar-collapsed .brand-copy, .sidebar-collapsed .menu-link span, .sidebar-collapsed .menu-group-toggle b, .sidebar-collapsed .menu-group-toggle > i, .sidebar-collapsed .menu-editor-link span { display: none; }
.sidebar-collapsed .sidebar-logo { padding: 0 19px; }
.sidebar-collapsed .menu-link, .sidebar-collapsed .menu-group-toggle, .sidebar-collapsed .menu-editor-link { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar-collapsed .menu-group-items { padding-left: 0; }

.panel-notice { position: fixed; z-index: 100; right: 22px; top: 78px; max-width: 390px; padding: 13px 16px; border-radius: 11px; color: white; background: var(--navy); box-shadow: 0 14px 35px rgba(9,31,53,.22); }
.panel-notice.error { background: #b82f48; }
.panel-notice.success { background: #16845a; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat-card, .mini-stat, .panel-card, .detail-hero, .fact-grid article, .action-strip { background: var(--surface); border: 1px solid rgba(224,230,238,.84); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card { min-height: 145px; padding: 19px; display: flex; justify-content: space-between; gap: 12px; overflow: hidden; position: relative; }
.stat-card > div { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.stat-card strong { font-size: 27px; line-height: 1; }
.stat-card span { color: var(--muted); margin: 7px 0 auto; }
.stat-card a { color: #5274a0; font-size: 12px; }
.stat-card a:hover { color: var(--primary); }
.stat-icon { width: 54px; height: 54px; flex: 0 0 54px; display: grid; place-items: center; border-radius: 15px; color: white; font-size: 27px; box-shadow: 0 10px 25px currentColor; }
.tone-purple { background: linear-gradient(135deg,#7258e8,#a375ef); }
.tone-yellow { background: linear-gradient(135deg,#f2a21a,#ffcc65); }
.tone-green { background: linear-gradient(135deg,#1aa877,#4fd4a5); }
.tone-cyan { background: linear-gradient(135deg,#27a9cf,#72d0e8); }
.tone-pink { background: linear-gradient(135deg,#df4a79,#f48bab); }
.tone-blue { background: linear-gradient(135deg,#397ae9,#78a9ff); }
.tone-lime { background: linear-gradient(135deg,#69a733,#a8d967); }
.tone-orange { background: linear-gradient(135deg,#e36b28,#f6a65b); }

.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; margin-bottom: 18px; align-items: start; }
.panel-card { min-width: 0; margin-bottom: 18px; overflow: hidden; }
.card-head { min-height: 58px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card-head a { color: var(--primary); font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 15px; color: #718096; background: #f8fafc; text-align: left; font-size: 11px; letter-spacing: .035em; text-transform: uppercase; white-space: nowrap; }
td { padding: 13px 15px; border-top: 1px solid #edf0f4; vertical-align: middle; }
tbody tr:hover { background: #fbfdff; }
td strong, td small { display: block; }
td small { color: var(--muted); font-size: 11px; margin-top: 4px; }
td code { padding: 3px 6px; color: #3b5e8b; background: #edf3fa; border-radius: 5px; }
.status { display: inline-flex; align-items: center; min-height: 23px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #edf1f5; color: #68758a; white-space: nowrap; }
.status-connected, .status-ready, .status-completed, .status-done, .status-applied, .status-active { color: #117049; background: #dff7ec; }
.status-running, .status-in-progress, .status-planned, .status-watching, .status-observed { color: #2862a0; background: #e1efff; }
.status-manual-review, .status-waiting, .status-new, .status-queued { color: #9a6500; background: #fff2cb; }
.status-failed, .status-reconnect-required, .status-cancelled, .status-disabled { color: #b13049; background: #ffe2e7; }
.priority { display: inline-flex; min-width: 36px; justify-content: center; padding: 4px 7px; border-radius: 6px; font-weight: 800; font-size: 11px; }
.priority-p1 { color: #c02b45; background: #ffe1e6; }
.priority-p2 { color: #9b6500; background: #ffefbf; }
.priority-p3 { color: #2c649f; background: #dfedff; }

.filter-card { padding: 17px; }
.filter-card .card-head { margin: -17px -17px 16px; }
.filter-grid { display: grid; grid-template-columns: repeat(3,minmax(150px,1fr)) auto auto; align-items: end; gap: 11px; }
label { display: grid; gap: 6px; color: #596981; font-size: 12px; font-weight: 650; }
input, select, textarea { width: 100%; min-height: 40px; padding: 8px 11px; color: var(--text); background: white; border: 1px solid #dbe2ea; border-radius: 8px; }
textarea { min-height: 120px; resize: vertical; }
button:not(.menu-group-toggle):not(.sidebar-toggle):not(.header-action):not(.logout), .button { min-height: 39px; padding: 0 14px; border-radius: 8px; color: white; background: var(--primary); display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-weight: 700; }
button.secondary, .button.secondary { color: #4b607b; background: #edf2f7; }
button.danger { background: var(--danger); }
button.compact, .button.compact { min-height: 31px; padding: 0 10px; font-size: 12px; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }

.mini-stat-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.mini-stat { padding: 15px 17px; display: flex; align-items: center; justify-content: space-between; }
.mini-stat strong { display: block; font-size: 22px; }
.mini-stat span { color: var(--muted); font-size: 12px; }
.mini-stat i { width: 42px; height: 42px; color: white; border-radius: 12px; display: grid; place-items: center; font-size: 21px; }
.action-strip { padding: 16px 18px; margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.action-strip p { margin: 0; color: var(--muted); }
.action-strip > div { display: flex; gap: 8px; }
.insight-row { min-height: 52px; padding: 0 17px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); }
.insight-row:first-child { border-top: 0; }
.insight-row span { display: flex; align-items: center; gap: 9px; }
.insight-row i { color: #e9a008; font-size: 20px; }

.detail-hero { padding: 22px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.detail-hero h2 { margin: 5px 0; font-size: 25px; }
.detail-hero a { color: var(--primary); }
.eyebrow { color: #7a8798; text-transform: uppercase; letter-spacing: .08em; font-size: 10px; font-weight: 800; }
.detail-status { display: flex; align-items: center; gap: 10px; }
.fact-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; margin-bottom: 18px; }
.fact-grid article { padding: 14px; }
.fact-grid span, .fact-grid strong { display: block; }
.fact-grid span { color: var(--muted); font-size: 11px; margin-bottom: 5px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; padding: 5px; width: max-content; background: #e7edf3; border-radius: 9px; }
.tabs button { min-height: 33px !important; color: #68778c !important; background: transparent !important; }
.tabs button[aria-selected="true"] { color: var(--navy) !important; background: white !important; box-shadow: 0 2px 8px rgba(21,43,70,.09); }
.board-tabs { display: flex; overflow-x: auto; gap: 2px; border-bottom: 1px solid var(--line); }
.board-tabs a { min-height: 45px; padding: 0 14px; display: flex; align-items: center; gap: 7px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.board-tabs a.active, .board-tabs a:hover { color: var(--primary); border-color: var(--primary); }
.board-tabs span { min-width: 22px; height: 22px; padding: 0 5px; display: grid; place-items: center; border-radius: 999px; background: #edf2f7; font-size: 10px; }
.decision-cell { min-width: 320px; }
.decision-cell span { display: block; margin: 3px 0; font-size: 12px; }
.empty-state { min-height: 220px; padding: 25px; color: var(--muted); display: grid; place-items: center; align-content: center; gap: 7px; text-align: center; }
.empty-state i { font-size: 42px; color: #82a3c5; }
.empty-state strong { color: var(--text); }

.module-grid, .plan-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 15px; padding: 17px; }
.module-card, .plan-card { padding: 17px; border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; gap: 11px; }
.module-card header, .plan-card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.module-card h3, .plan-card h3 { margin: 0; font-size: 15px; }
.module-card p, .plan-card p { margin: 0; color: var(--muted); line-height: 1.55; }
.module-card footer, .plan-card footer { margin-top: auto; padding-top: 8px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.plan-card.featured { border-color: #9dbef8; box-shadow: 0 10px 30px rgba(59,130,246,.12); }
.plan-head { display: grid; gap: 4px; }
.plan-head span { width: max-content; padding: 4px 7px; color: #2d67b3; background: #e4efff; border-radius: 6px; font-size: 10px; font-weight: 900; letter-spacing: .06em; }
.plan-head strong { font-size: 20px; }
.plan-head small { color: var(--muted); }
.plan-card dl { margin: 0; display: grid; gap: 7px; }
.plan-card dl div { display: flex; justify-content: space-between; gap: 10px; padding-bottom: 7px; border-bottom: 1px dashed var(--line); }
.plan-card dt { color: var(--muted); }
.plan-card dd { margin: 0; font-weight: 800; }
.module-card p, td p { color: var(--muted); line-height: 1.5; }

.panel-dialog { width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 16px; color: var(--text); box-shadow: 0 30px 90px rgba(6,25,45,.3); }
.panel-dialog::backdrop { background: rgba(8,25,42,.55); backdrop-filter: blur(3px); }
.dialog-head { padding: 17px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-head button { width: 35px; min-height: 35px !important; padding: 0 !important; color: #607089 !important; background: #eef2f6 !important; }
.dialog-body { padding: 20px; overflow: auto; }
.dialog-actions { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.diff-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.diff-grid article { padding: 14px; border-radius: 10px; border: 1px solid var(--line); background: #f8fafc; }
.diff-grid h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.diff-grid p { white-space: pre-wrap; line-height: 1.55; }
.dialog-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: 17px; min-height: 17px; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 15%, rgba(70,116,233,.2), transparent 28%), radial-gradient(circle at 85% 75%, rgba(43,200,180,.18), transparent 24%), #edf2f7; }
.login-card { width: min(430px,100%); padding: 34px; border-radius: 20px; background: white; box-shadow: 0 25px 70px rgba(18,42,68,.16); }
.login-brand { margin-bottom: 27px; }
.login-brand > div { display: grid; }
.login-brand strong { font-size: 18px; }
.login-brand small { color: var(--muted); }
.login-card h1 { margin: 0 0 7px; font-size: 26px; }
.login-card > p { margin: 0 0 21px; color: var(--muted); }
.login-card form { display: grid; gap: 14px; }
.login-card form button { min-height: 44px !important; margin-top: 4px; }
.login-foot { display: block; margin-top: 20px; color: #98a3b2; text-align: center; }
.login-error { padding: 11px 13px; margin-bottom: 14px; border-radius: 8px; color: #a82b42; background: #ffe6eb; }

@media (max-width: 1180px) {
    .stat-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .module-grid, .plan-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .header-action span, .header-user > span:last-child { display: none; }
}

@media (max-width: 840px) {
    :root { --sidebar-width: 260px; }
    .sidebar { transform: translateX(-100%); }
    .mobile-sidebar-open .sidebar { transform: translateX(0); }
    .mobile-sidebar-open::after { content: ""; position: fixed; inset: 0; z-index: 45; background: rgba(7,23,39,.48); }
    .admin-header { left: 0; padding: 0 14px; }
    .main-content { padding: calc(var(--header-height) + 19px) 14px 28px; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .fact-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .filter-grid { grid-template-columns: 1fr 1fr; }
    .global-search { width: min(370px, 47vw); }
    .sidebar-collapsed { --sidebar-width: 260px; }
    .sidebar-collapsed .brand-copy, .sidebar-collapsed .menu-link span, .sidebar-collapsed .menu-group-toggle b, .sidebar-collapsed .menu-group-toggle > i, .sidebar-collapsed .menu-editor-link span { display: initial; }
    .sidebar-collapsed .menu-link, .sidebar-collapsed .menu-group-toggle, .sidebar-collapsed .menu-editor-link { justify-content: initial; padding-left: 12px; padding-right: 12px; }
}

@media (max-width: 570px) {
    .stat-grid, .mini-stat-grid, .module-grid, .plan-grid, .fact-grid, .diff-grid, .dialog-form-grid { grid-template-columns: 1fr; }
    .stat-card { min-height: 126px; }
    .filter-grid { grid-template-columns: 1fr; }
    .page-heading time { display: none; }
    .global-search { width: 44px; padding: 0 12px; }
    .global-search input { opacity: 0; position: absolute; pointer-events: none; }
    .global-search:focus-within { position: fixed; left: 59px; right: 9px; width: auto; z-index: 95; }
    .global-search:focus-within input { opacity: 1; position: static; pointer-events: auto; }
    .header-action { display: none; }
    .action-strip, .detail-hero { align-items: flex-start; flex-direction: column; }
    .action-strip > div { width: 100%; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.company-settings { padding: 24px; max-width: 980px; }
.company-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 22px; }
.company-fields label { display: flex; flex-direction: column; gap: 8px; font-weight: 600; }
.company-fields .company-phone { grid-column: 1 / -1; }
.company-fields input, .company-fields textarea { width: 100%; box-sizing: border-box; padding: 12px; border: 1px solid #d6dce5; border-radius: 8px; background: #fff; color: #17243a; font: inherit; font-weight: 400; }
.company-fields textarea { resize: vertical; min-height: 108px; line-height: 1.6; }
.company-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 20px; margin-top: 26px; }
.company-message { max-width: 980px; padding: 16px 22px; margin-bottom: 18px; background: #e9f6ee; border: 1px solid #b7ddc5; border-radius: 8px; color: #205837; }
.company-error { background: #fff3ed; border-color: #edd0bd; color: #8c3a19; }
@media (max-width: 700px) { .company-fields { grid-template-columns: 1fr; } .company-settings { padding: 18px; } }
