/* === Variables === */
:root {
  --c-primary: #4f46e5;
  --c-primary-h: #4338ca;
  --c-primary-bg: #eef2ff;
  --c-sidebar: #0f172a;
  --c-sidebar-item: #1e293b;
  --c-bg: #f8fafc;
  --c-card: #ffffff;
  --c-border: #e2e8f0;
  --c-text: #0f172a;
  --c-text-2: #64748b;
  --c-text-3: #94a3b8;
  --c-ok: #10b981; --c-ok-bg: #ecfdf5; --c-ok-text: #047857;
  --c-warn: #f59e0b; --c-warn-bg: #fffbeb; --c-warn-text: #b45309;
  --c-err: #ef4444; --c-err-bg: #fef2f2; --c-err-text: #b91c1c;
  --c-info: #3b82f6; --c-info-bg: #eff6ff; --c-info-text: #1d4ed8;
  --r: 8px;
  --r-lg: 12px;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--c-bg); color: var(--c-text); line-height: 1.5; font-size: 14px; -webkit-font-smoothing: antialiased; }
h1,h2,h3 { font-weight: 600; line-height: 1.2; }
a { color: var(--c-primary); text-decoration: none; transition: opacity .2s; }
a:hover { opacity: .8; }
.hidden { display: none !important; }
.text-muted { color: var(--c-text-2); font-size: 13px; }
.text-ok { color: var(--c-ok); }
.mb-4 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }

/* === Login Screen === */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #0f172a; position: relative; overflow: hidden; }
.login-screen::before { content: ''; position: absolute; inset: 0; background-image: radial-gradient(#334155 1px, transparent 1px); background-size: 24px 24px; opacity: 0.15; }
.login-screen::after { content: ''; position: absolute; width: 600px; height: 600px; background: radial-gradient(circle, rgba(99,102,241,0.15) 0%, transparent 70%); top: 50%; left: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.login-card { position: relative; background: var(--c-card); border-radius: 16px; padding: 48px 40px; width: 400px; max-width: 90vw; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); text-align: center; }
.login-logo { width: 56px; height: 56px; background: var(--c-primary-bg); color: var(--c-primary); border-radius: 14px; display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; }
.login-card h1 { font-size: 24px; margin-bottom: 6px; letter-spacing: -0.5px; }
.login-sub { color: var(--c-text-2); margin-bottom: 32px; font-size: 14px; }
.login-card .form-group { text-align: left; margin-bottom: 20px; }

/* === Shell Layout === */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--c-sidebar); color: #e2e8f0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; border-right: 1px solid #1e293b; }
.sb-brand { height: 64px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #1e293b; font-weight: 600; font-size: 16px; letter-spacing: -0.3px; gap: 10px; }
.sb-logo { width: 32px; height: 32px; background: var(--c-primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; }

#nav { flex: 1; padding: 20px 12px; overflow-y: auto; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: #64748b; font-weight: 600; margin: 24px 12px 8px; }
.nav-group:first-child { margin-top: 0; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: #94a3b8; font-size: 14px; font-weight: 500; margin-bottom: 2px; transition: all .2s; cursor: pointer; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: #f8fafc; }
.nav-item.active { background: var(--c-primary); color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.nav-item .ni { opacity: 0.7; }
.nav-item.active .ni { opacity: 1; }

.sb-footer { padding: 16px 20px; border-top: 1px solid #1e293b; display: flex; align-items: center; justify-content: space-between; background: rgba(0,0,0,0.2); }
.sb-user { display: flex; align-items: center; gap: 10px; }
.sb-avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, #6366f1, #a855f7); border: 2px solid #1e293b; }
.sb-info { display: flex; flex-direction: column; line-height: 1.2; }
.sb-name { font-size: 13px; font-weight: 500; color: #f1f5f9; }
.sb-role { font-size: 11px; color: #64748b; }

/* === Main Area === */
.main-area { padding: 32px 40px; overflow-y: auto; max-width: 1400px; margin: 0 auto; width: 100%; }
.page { display: none; flex-direction: column; gap: 24px; animation: fadeIn .3s ease; }
.page.active { display: flex; }
.page-hd { margin-bottom: 8px; }
.page-title { font-size: 24px; color: var(--c-text); letter-spacing: -0.5px; margin-bottom: 4px; }
.page-desc { color: var(--c-text-2); font-size: 14px; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* === Cards === */
.card { background: var(--c-card); border-radius: var(--r-lg); border: 1px solid var(--c-border); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; overflow: hidden; }
.card-hd { padding: 16px 20px; border-bottom: 1px solid var(--c-bg); display: flex; align-items: center; justify-content: space-between; background: #fff; }
.card-hd h3 { font-size: 15px; color: var(--c-text); font-weight: 600; }
.card-hd.wrap { flex-wrap: wrap; gap: 12px; }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--c-border); background: #f8fafc; display: flex; justify-content: flex-end; }

/* === Stats === */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.stat-card { background: #fff; border: 1px solid var(--c-border); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 3px; background: var(--c-primary); opacity: 0.5; }
.stat-label { font-size: 13px; color: var(--c-text-2); font-weight: 500; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-val { font-size: 30px; font-weight: 700; color: var(--c-text); letter-spacing: -1px; line-height: 1.1; }
.stat-sub { font-size: 12px; color: var(--c-text-3); margin-top: 6px; display: flex; align-items: center; gap: 4px; }

/* === Tables === */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { background: #f9fafb; color: var(--c-text-2); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; padding: 12px 20px; text-align: left; border-bottom: 1px solid var(--c-border); }
tbody td { padding: 14px 20px; border-bottom: 1px solid #f1f5f9; color: var(--c-text); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
td.empty { text-align: center; color: var(--c-text-3); padding: 40px; font-style: italic; }
.wrap-header { padding-bottom: 12px; }

/* === Forms === */
label { display: block; font-size: 13px; font-weight: 500; color: var(--c-text); margin-bottom: 6px; }
.input-wrap { position: relative; }
.input-ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--c-text-3); pointer-events: none; transition: color .2s; }
input:focus + .input-ico, .input-wrap:focus-within .input-ico { color: var(--c-primary); }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--c-border); border-radius: var(--r); font-size: 14px; background: #fff; transition: all .2s; color: var(--c-text); }
.input-wrap input { padding-left: 38px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-bg); }
input::placeholder { color: #cbd5e1; }

.form-grid { display: grid; gap: 20px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.form-stack { display: flex; flex-direction: column; gap: 16px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-bar select, .filter-bar input { width: auto; min-width: 120px; padding: 6px 10px; font-size: 13px; height: 34px; }
.file-box { border: 1px dashed var(--c-border); padding: 20px; border-radius: var(--r); text-align: center; background: #f9fafb; transition: .2s; }
.file-box:hover { border-color: var(--c-primary); background: #f1f5f9; }
.file-box input { border: none; background: transparent; padding: 0; }

/* === Buttons === */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; font-size: 14px; padding: 9px 16px; border-radius: var(--r); cursor: pointer; transition: all .2s; border: 1px solid transparent; line-height: 1; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--c-primary); color: #fff; box-shadow: 0 1px 2px rgba(79, 70, 229, 0.3); }
.btn-primary:hover { background: var(--c-primary-h); box-shadow: 0 4px 6px rgba(79, 70, 229, 0.25); }
.btn-outline { background: #fff; border-color: var(--c-border); color: var(--c-text); }
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-ghost { background: transparent; color: var(--c-text-2); padding: 6px 12px; }
.btn-ghost:hover { background: #f1f5f9; color: var(--c-text); }
.btn-danger { background: var(--c-err); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { background: none; border: none; color: #94a3b8; padding: 6px; cursor: pointer; border-radius: 6px; transition: .2s; }
.btn-icon:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* === Badges === */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; line-height: 1.4; letter-spacing: 0.3px; }
.badge-ok { background: var(--c-ok-bg); color: var(--c-ok-text); }
.badge-warn { background: var(--c-warn-bg); color: var(--c-warn-text); }
.badge-err { background: var(--c-err-bg); color: var(--c-err-text); }
.badge-info { background: var(--c-info-bg); color: var(--c-info-text); }
.badge-gray { background: #f1f5f9; color: var(--c-text-2); }

/* === Pager === */
.pager { display: flex; gap: 4px; }
.pager button { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--c-border); background: #fff; border-radius: 4px; font-size: 12px; color: var(--c-text-2); cursor: pointer; transition: .2s; }
.pager button:hover:not(:disabled) { border-color: var(--c-primary); color: var(--c-primary); }
.pager button.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.pager button:disabled { opacity: 0.5; cursor: not-allowed; background: #f1f5f9; }
.pager-info { font-size: 12px; color: var(--c-text-3); align-self: center; margin: 0 8px; }

/* === Gen Result === */
.gen-result { background: #f8fafc; border-top: 1px solid var(--c-border); padding-top: 20px; margin-top: 0; }
.result-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.result-title { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--c-text); }
.gen-result pre { font-family: 'Menlo', 'Monaco', monospace; font-size: 12px; line-height: 1.6; background: #fff; border: 1px solid var(--c-border); padding: 12px; border-radius: 8px; max-height: 200px; overflow-y: auto; color: var(--c-text-2); }

/* === Toast === */
#toasts { position: fixed; top: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #fff; padding: 14px 18px; border-radius: 8px; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 10px; min-width: 300px; border-left: 4px solid transparent; animation: slideIn .3s cubic-bezier(0.16, 1, 0.3, 1); }
.toast-ok { border-left-color: var(--c-ok); }
.toast-err { border-left-color: var(--c-err); }
.toast-info { border-left-color: var(--c-info); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* === Modal === */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.6); backdrop-filter: blur(2px); z-index: 9000; display: flex; align-items: center; justify-content: center; animation: fadeIn .2s ease; }
.modal-box { background: #fff; width: 440px; max-width: 90vw; border-radius: 12px; box-shadow: var(--shadow-lg); overflow: hidden; animation: scaleIn .2s cubic-bezier(0.16, 1, 0.3, 1); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--c-border); display: flex; justify-content: space-between; align-items: center; background: #f9fafb; }
.modal-header h3 { font-size: 16px; color: var(--c-text); }
.modal-x { background: none; border: none; font-size: 24px; color: var(--c-text-3); cursor: pointer; line-height: 1; padding: 0 4px; }
.modal-x:hover { color: var(--c-text); }
.modal-body { padding: 24px 20px; }
.modal-body { max-height: 78vh; overflow: auto; }
.modal-script { width: min(1080px, 92vw); }
.modal-body-script { padding: 0; }
.script-modal { display: flex; flex-direction: column; gap: 0; background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%); }
.script-stat-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; padding: 20px; border-bottom: 1px solid var(--c-border); background: #fff; }
.script-stat-card { border: 1px solid var(--c-border); border-radius: 10px; background: #f8fafc; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.script-stat-label { font-size: 11px; color: var(--c-text-3); text-transform: uppercase; letter-spacing: .4px; }
.script-stat-value { font-size: 14px; color: var(--c-text); font-weight: 600; word-break: break-word; }
.script-modal-grid { display: grid; grid-template-columns: 1.3fr .9fr; gap: 20px; padding: 20px; }
.script-panel { border: 1px solid var(--c-border); border-radius: 12px; background: #fff; padding: 18px; box-shadow: var(--shadow-sm); min-width: 0; }
.script-panel-hd { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.script-panel-hd h4 { font-size: 15px; color: var(--c-text); }
.script-empty { border: 1px dashed var(--c-border); border-radius: 10px; padding: 28px 20px; color: var(--c-text-3); text-align: center; background: #f8fafc; }
.schema-card-list { display: flex; flex-direction: column; gap: 12px; }
.schema-card { border: 1px solid var(--c-border); border-radius: 10px; padding: 14px 16px; background: linear-gradient(180deg, #fff 0%, #f8fafc 100%); }
.schema-card-hd { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.schema-card-title { font-size: 14px; font-weight: 600; color: var(--c-text); }
.schema-card-key { font-size: 12px; color: var(--c-text-3); margin-top: 2px; font-family: 'Menlo', 'Monaco', monospace; }
.schema-card-desc { color: var(--c-text-2); font-size: 13px; margin-bottom: 12px; line-height: 1.6; }
.schema-meta-row { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.schema-meta-label { font-size: 12px; color: var(--c-text-3); }
.schema-code { display: inline-flex; max-width: 100%; white-space: pre-wrap; word-break: break-word; border-radius: 8px; background: #f1f5f9; color: var(--c-text); padding: 8px 10px; font-size: 12px; border: 1px solid #e2e8f0; font-family: 'Menlo', 'Monaco', monospace; }
.schema-chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.schema-chip { display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 999px; background: #eef2ff; color: #4338ca; font-size: 12px; border: 1px solid #c7d2fe; }
.script-json-view { width: 100%; min-height: 420px; resize: vertical; font-family: 'Menlo', 'Monaco', monospace; line-height: 1.6; background: #0f172a; color: #e2e8f0; border: 1px solid #1e293b; border-radius: 10px; padding: 14px 16px; }
.script-json-edit { background: #0b1220; }
.script-edit-grid label span { display: inline-block; margin-bottom: 6px; }
.script-modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px 20px; border-top: 1px solid var(--c-border); background: #fff; position: sticky; bottom: 0; }
.modal-user { width: min(760px, 92vw); }
.modal-user-md { width: min(820px, 92vw); }
.modal-user-lg { width: min(1040px, 94vw); }
.modal-body-user { padding: 0; }
.user-modal { display: flex; flex-direction: column; gap: 0; background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%); }
.user-summary-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px; border-bottom: 1px solid var(--c-border); background: #fff; }
.user-summary-label { font-size: 11px; color: var(--c-text-3); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }
.user-summary-name { font-size: 18px; color: var(--c-text); font-weight: 700; letter-spacing: -.3px; }
.user-summary-extra { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-panel { padding: 20px; border-bottom: 1px solid var(--c-border); background: #fff; }
.user-panel h4 { font-size: 15px; color: var(--c-text); margin-bottom: 12px; }
.user-modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px 20px; background: #fff; border-top: 1px solid var(--c-border); }
.user-binding-stack { display: flex; flex-direction: column; gap: 16px; padding: 20px; }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* === Grids === */
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; }
.h-fit { height: fit-content; }
.v-stack { display: flex; flex-direction: column; gap: 12px; }

/* === Responsive === */
@media (max-width: 1024px) {
  .shell { grid-template-columns: 200px 1fr; }
  .grid-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .shell { display: block; }
  .sidebar { height: auto; position: relative; flex-direction: row; align-items: center; padding: 10px 16px; justify-content: space-between; border-bottom: 1px solid #1e293b; border-right: none; }
  .sb-brand { border: none; padding: 0; height: auto; }
  #nav { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--c-sidebar); padding: 10px; z-index: 100; border-bottom: 1px solid #1e293b; box-shadow: var(--shadow-lg); }
  .sidebar:hover #nav { display: block; }
  .sb-footer { display: none; }
  .main-area { padding: 20px 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .cols-2, .cols-3 { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: span 1; }
  .filter-bar { display: flex; flex-direction: column; align-items: stretch; }
  .filter-bar select, .filter-bar input { width: 100%; }
  .script-stat-grid { grid-template-columns: 1fr 1fr; }
  .script-modal-grid { grid-template-columns: 1fr; }
  .script-modal-footer { flex-direction: column-reverse; }
  .script-modal-footer .btn { width: 100%; }
  .user-summary-bar { flex-direction: column; align-items: flex-start; }
  .user-modal-footer { flex-direction: column-reverse; }
  .user-modal-footer .btn { width: 100%; }
}
