@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap');

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #172033;
  --muted: #697386;
  --line: #e5e9f0;
  --primary: #991b35;
  --primary-dark: #751127;
  --primary-soft: #fff1f3;
  --success: #13795b;
  --success-soft: #eaf8f3;
  --warning: #a15c00;
  --warning-soft: #fff6df;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --sidebar: #121926;
  --shadow: 0 12px 34px rgba(22, 32, 51, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.55 "DM Sans", sans-serif; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: Manrope, sans-serif; letter-spacing: -.025em; }
h1 { font-size: 25px; margin-bottom: 0; }
h2 { font-size: 20px; margin-bottom: 5px; }
h3 { font-size: 18px; }
code { border-radius: 6px; background: #f0f2f5; color: #4d5667; padding: 2px 7px; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.eyebrow { margin-bottom: 4px; color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; display: flex; width: 248px; flex-direction: column; background: var(--sidebar); color: #d4dae4; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; min-height: 82px; padding: 18px 22px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand strong { color: white; font: 700 17px Manrope, sans-serif; }
.sidebar-brand small { color: #8f9aad; font-size: 11px; }
.brand-mark { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border-radius: 11px; background: linear-gradient(145deg, #c92e4b, #83142d); color: white; font: 800 18px Manrope, sans-serif; box-shadow: 0 8px 18px rgba(190,35,67,.25); }
.sidebar-nav { display: grid; gap: 5px; padding: 20px 14px; }
.sidebar-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: 10px; color: #aeb7c6; font-weight: 600; transition: .18s ease; }
.sidebar-nav a span { display: grid; width: 22px; place-items: center; font-size: 17px; }
.sidebar-nav a:hover { background: rgba(255,255,255,.05); color: white; }
.sidebar-nav a.is-active { background: rgba(202,46,76,.18); color: #fff; box-shadow: inset 3px 0 #df4967; }
.sidebar-footer { display: grid; gap: 8px; margin-top: auto; padding: 18px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer a, .sidebar-footer button { width: 100%; padding: 9px 11px; border: 0; border-radius: 8px; background: transparent; color: #9fa9b9; text-align: left; cursor: pointer; }
.sidebar-footer a:hover, .sidebar-footer button:hover { background: rgba(255,255,255,.06); color: white; }
.main-panel { min-height: 100vh; margin-left: 248px; }
.topbar { display: flex; align-items: center; gap: 16px; min-height: 82px; padding: 14px 32px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.88); backdrop-filter: blur(10px); }
.topbar > div:nth-child(2) { flex: 1; }
.topbar .eyebrow { color: #8992a2; }
.topbar-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; }
.topbar-status span, .status-dot { width: 9px; height: 9px; border-radius: 50%; background: #1fba83; box-shadow: 0 0 0 4px #e2f8f0; }
.mobile-menu { display: none; border: 0; background: transparent; font-size: 23px; cursor: pointer; }
.content { width: min(1480px, 100%); margin: 0 auto; padding: 28px 32px 56px; }

.button { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; gap: 8px; padding: 9px 15px; border: 1px solid transparent; border-radius: 9px; font-weight: 700; cursor: pointer; transition: .16s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .48; cursor: not-allowed; transform: none; }
.button--primary { background: var(--primary); color: white; box-shadow: 0 7px 16px rgba(153,27,53,.17); }
.button--primary:hover { background: var(--primary-dark); }
.button--secondary { border-color: var(--line); background: white; color: #485267; }
.button--secondary:hover { border-color: #c9cfda; background: #fafbfc; }
.button--light { background: white; color: var(--primary); }
.button--danger { background: var(--danger); color: white; }
.button--danger-ghost { border-color: #f1c9c5; background: var(--danger-soft); color: var(--danger); }
.button--block { width: 100%; }

.alert { position: relative; margin-bottom: 20px; padding: 13px 45px 13px 15px; border: 1px solid; border-radius: 11px; font-weight: 600; }
.alert button { position: absolute; top: 7px; right: 8px; border: 0; background: transparent; color: inherit; font-size: 22px; cursor: pointer; }
.alert--success { border-color: #bde7d8; background: var(--success-soft); color: var(--success); }
.alert--error { border-color: #f0c3be; background: var(--danger-soft); color: var(--danger); }

.welcome-card { display: flex; align-items: center; justify-content: space-between; gap: 30px; min-height: 190px; margin-bottom: 22px; padding: 34px 38px; border-radius: 18px; background: linear-gradient(120deg, #8f1730, #bd2948); color: white; box-shadow: 0 16px 35px rgba(137,22,46,.18); }
.welcome-card .eyebrow { color: #ffdce3; }
.welcome-card h2 { max-width: 640px; font-size: 30px; }
.welcome-card p:not(.eyebrow) { max-width: 700px; margin: 0; color: #ffe9ed; font-size: 15px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card { padding: 21px 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 4px 16px rgba(20,31,52,.035); }
.stat-card > span, .stat-card small { display: block; color: var(--muted); }
.stat-card strong { display: block; margin: 6px 0 4px; font: 800 31px Manrope, sans-serif; }
.stat-card strong em { color: #9aa2b0; font-size: 16px; font-style: normal; }
.two-column { display: grid; grid-template-columns: minmax(0,1.25fr) minmax(300px,.75fr); gap: 20px; }
.two-column.align-start { align-items: start; }
.panel { margin-bottom: 20px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 4px 16px rgba(20,31,52,.035); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.panel-head p { margin-bottom: 0; }
.workflow, .security-list { display: grid; gap: 16px; margin: 0; padding: 0; list-style: none; }
.workflow li, .security-list li { display: flex; align-items: flex-start; gap: 12px; }
.workflow li > span, .security-list li > span { display: grid; width: 30px; height: 30px; flex: 0 0 30px; place-items: center; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-weight: 800; }
.workflow p, .security-list p { margin: 2px 0 0; color: var(--muted); }
.status-list { display: grid; gap: 12px; }
.status-list > div { display: flex; align-items: center; gap: 12px; padding: 13px; border-radius: 10px; background: var(--surface-soft); }
.status-list strong, .status-list small { display: block; }
.status-list small { color: var(--muted); }

.page-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-actions p { margin: 0; }
.page-actions > div:last-child { display: flex; flex-wrap: wrap; gap: 9px; }
.page-actions form { display: inline-flex; }
.search-field { min-width: 230px; color: var(--muted); font-size: 12px; }
.search-field input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); outline: none; }
.search-field input:focus { border-color: #bd7585; box-shadow: 0 0 0 3px var(--primary-soft); }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 13px; border-bottom: 1px solid var(--line); color: #818a99; font-size: 11px; letter-spacing: .055em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 14px 13px; border-bottom: 1px solid #edf0f4; color: #3a4457; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }
td strong, td small { display: block; }
td small { max-width: 380px; margin-top: 2px; color: var(--muted); }
.actions-cell { width: 1%; text-align: right; white-space: nowrap; }
.actions-cell form { display: inline; }
.icon-button { padding: 5px 7px; border: 0; background: transparent; color: #536077; font-weight: 700; cursor: pointer; }
.icon-button:hover { color: var(--primary); }
.icon-button--danger { color: var(--danger); }
.badge, .source-tag { display: inline-flex; align-items: center; width: max-content; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--muted, .source-tag { background: #f0f2f5; color: #697386; }
.table-link { color: var(--primary); font-size: 12px; font-weight: 700; white-space: nowrap; }
.empty-state { padding: 42px 20px; color: var(--muted); text-align: center; }
.inline-select label { color: var(--muted); font-size: 12px; }
.inline-select select { min-width: 180px; margin-left: 7px; padding: 8px 28px 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.zone-switcher { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-color: #ead0d6; background: linear-gradient(120deg,#fff8f9,#fff); }
.zone-switcher h2, .zone-switcher p { margin-bottom: 0; }
.zone-package-panel { margin-top: 20px; }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 18px; }
.entity-card { display: flex; min-height: 245px; flex-direction: column; padding: 21px; border: 1px solid var(--line); border-radius: var(--radius); background: white; box-shadow: 0 4px 16px rgba(20,31,52,.035); }
.entity-card.is-selected { border-color: #c86e80; box-shadow: 0 0 0 3px var(--primary-soft), 0 8px 22px rgba(153,27,53,.08); }
.entity-card__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.entity-icon { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 10px; background: var(--primary-soft); color: var(--primary); font: 800 15px Manrope, sans-serif; }
.entity-card h2 { margin-bottom: 2px; }
.entity-card p { min-height: 44px; margin: 12px 0; color: var(--muted); }
.entity-meta { display: flex; gap: 22px; margin-top: auto; padding: 13px 0; border-top: 1px solid var(--line); color: var(--muted); }
.entity-meta strong { color: var(--ink); }
.entity-actions { display: flex; gap: 8px; }
.entity-actions form, .entity-actions .button { flex: 1; }
.entity-actions .button { width: 100%; }
.content-preview { padding: 28px; border-radius: 13px; background: linear-gradient(145deg,#fff5f6,#fff); box-shadow: inset 0 0 0 1px #f5dce1; }
.content-preview > span { color: var(--primary); font-weight: 800; }
.content-preview h3 { margin: 10px 0 8px; font-size: 26px; }
.content-preview p { color: var(--muted); }
.content-preview footer { margin-top: 25px; padding-top: 14px; border-top: 1px solid #efcdd4; color: #727b8a; font-size: 12px; }
.menu-list { display: grid; }
.menu-list > div { display: grid; grid-template-columns: 34px minmax(0,1fr) auto auto auto; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.menu-list > div:last-child { border-bottom: 0; }
.menu-list strong, .menu-list small { display: block; }
.menu-list small { color: var(--muted); }
.drag-handle { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 7px; background: #f0f2f5; color: #798292; font-size: 11px; }
.security-hero { display: flex; align-items: center; justify-content: space-between; gap: 30px; margin-bottom: 20px; padding: 28px; border: 1px solid #edd3d9; border-radius: var(--radius); background: linear-gradient(120deg,#fff7f8,#fff); }
.security-hero p:last-child { max-width: 720px; margin: 0; color: var(--muted); }
.database-card { display: flex; align-items: flex-start; gap: 13px; padding: 18px; border: 1px solid #c9ebde; border-radius: 12px; background: var(--success-soft); }
.database-card .status-dot { margin-top: 7px; flex: 0 0 9px; }
.database-card p { margin: 3px 0 0; color: #427565; }

.modal { width: min(650px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: 17px; background: transparent; color: var(--ink); box-shadow: 0 28px 70px rgba(12,20,34,.27); }
.modal::backdrop { background: rgba(13,20,31,.62); backdrop-filter: blur(3px); }
.modal-card { display: flex; max-height: calc(100vh - 28px); flex-direction: column; overflow: hidden; border-radius: 17px; background: white; }
.modal-card--small { width: min(500px, calc(100vw - 28px)); }
.modal-card--confirm { width: min(430px, calc(100vw - 28px)); }
.modal-card > header, .modal-card > footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; }
.modal-card > header { border-bottom: 1px solid var(--line); }
.modal-card > header h2 { margin: 0; }
.modal-card > header button { display: grid; width: 32px; height: 32px; place-items: center; border: 0; border-radius: 8px; background: #f2f4f7; color: #647085; font-size: 21px; cursor: pointer; }
.modal-card > footer { justify-content: flex-end; border-top: 1px solid var(--line); background: var(--surface-soft); }
.modal-body { overflow-y: auto; padding: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.form-stack { display: grid; gap: 16px; }
.span-2 { grid-column: span 2; }
.field { display: grid; gap: 6px; color: #465168; font-weight: 700; }
.field > span:first-child { font-size: 12px; }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #d9dee7; border-radius: 9px; background: white; color: var(--ink); outline: none; font-weight: 400; }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #b66375; box-shadow: 0 0 0 3px var(--primary-soft); }
.check-field { display: flex; align-items: center; gap: 9px; color: #4c576b; font-weight: 600; }
.check-field input { width: 17px; height: 17px; accent-color: var(--primary); }
.form-hint { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-soft); color: var(--muted); font-size: 12px; }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 60px; }
.password-field button { position: absolute; top: 6px; right: 7px; padding: 5px 7px; border: 0; background: transparent; color: var(--primary); font-size: 12px; font-weight: 700; cursor: pointer; }
.upload-field { display: grid; gap: 9px; margin-top: 17px; padding: 20px; border: 1px dashed #bcc4d0; border-radius: 12px; background: var(--surface-soft); }
.upload-field > span { font-weight: 800; }
.upload-field small { color: var(--muted); }
.template-link { color: var(--primary); font-weight: 800; }
.import-links { display: flex; flex-wrap: wrap; gap: 10px 20px; margin: 16px 0 4px; }

.login-page { min-height: 100vh; background: radial-gradient(circle at 20% 10%,#fce7eb,transparent 34%), linear-gradient(145deg,#f7f8fb,#eef1f5); }
.login-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-card { width: min(430px,100%); padding: 38px; border: 1px solid rgba(255,255,255,.8); border-radius: 22px; background: rgba(255,255,255,.94); box-shadow: 0 24px 70px rgba(20,30,50,.12); }
.login-card .brand-mark { margin-bottom: 25px; }
.login-card h1 { margin-bottom: 9px; font-size: 28px; }
.login-card > .muted { margin-bottom: 24px; }
.login-note { margin: 19px 0 0; color: var(--muted); font-size: 12px; text-align: center; }
.login-note strong { color: var(--ink); }
.sidebar-backdrop { display: none; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .card-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-102%); transition: transform .22s ease; }
  .sidebar.is-open { transform: translateX(0); }
  .main-panel { margin-left: 0; }
  .mobile-menu { display: block; }
  .topbar { padding: 13px 18px; }
  .topbar-status { display: none; }
  .content { padding: 20px 16px 42px; }
  .sidebar-backdrop.is-open { position: fixed; inset: 0; z-index: 20; display: block; background: rgba(0,0,0,.42); }
  .welcome-card, .security-hero, .page-actions, .zone-switcher { align-items: flex-start; flex-direction: column; }
  .welcome-card { padding: 27px; }
  .page-actions > div:last-child { width: 100%; }
  .page-actions .button { flex: 1; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .search-field { width: 100%; }
}

@media (max-width: 590px) {
  .stat-grid, .card-grid, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .stat-card { padding: 18px; }
  .panel { padding: 17px; }
  .welcome-card h2 { font-size: 25px; }
  .modal-card > header, .modal-card > footer, .modal-body { padding: 16px; }
  .modal-card > footer .button { flex: 1; }
  .menu-list > div { grid-template-columns: 32px minmax(0,1fr) auto; }
  .menu-list > div .badge { display: none; }
}


/* v16: package display mode switch */
.package-display-panel{ margin-bottom: 20px; }
.package-sort-switch{ display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; }
.sort-mode-card{ min-height:112px; display:grid; align-content:center; gap:7px; padding:18px 20px; text-align:left; color:var(--text,#293246); border:1px solid #dfe5ef; border-radius:16px; background:#fff; cursor:pointer; font:inherit; transition:border-color .18s ease,box-shadow .18s ease,transform .18s ease; }
.sort-mode-card strong{ color:#151c29; font-size:15px; }
.sort-mode-card span{ color:#697386; font-size:12px; line-height:1.6; }
.sort-mode-card:hover{ transform:translateY(-1px); border-color:#9eb7dc; box-shadow:0 12px 28px rgba(24,42,75,.08); }
.sort-mode-card.is-active{ border-color:#2468c9; box-shadow:0 0 0 3px rgba(36,104,201,.10); background:#f6f9ff; }
@media (max-width:720px){ .package-sort-switch{ grid-template-columns:1fr; } }


/* v17: configurable group_name filter ordering */
.package-group-order-panel{ margin-top: 18px; }
.group-order-form{ display: grid; gap: 18px; }
.group-order-list{ display: grid; gap: 10px; }
.group-order-row{ display: grid; grid-template-columns: 52px minmax(0,1fr) 112px; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.group-order-position{ width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; background: #eef3fa; color: #0b2d61; font-size: 13px; font-weight: 900; }
.group-order-name{ min-width: 0; display: grid; gap: 2px; }
.group-order-name strong{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-order-name small{ color: var(--muted); font-size: 11px; }
.group-order-input{ display: grid; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 800; }
.group-order-input input{ width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); font: inherit; font-size: 14px; }
.group-order-input input:focus{ outline: 0; border-color: #7da3dc; box-shadow: 0 0 0 3px rgba(11,45,97,.09); }
.panel-actions{ display: flex; justify-content: flex-end; }
@media (max-width: 600px){ .group-order-row{ grid-template-columns: 46px minmax(0,1fr); } .group-order-input{ grid-column: 1 / -1; grid-template-columns: auto minmax(100px,140px); align-items: center; justify-content: end; } .panel-actions .button{ width: 100%; } }
