:root {
  --bg: #0f172a;
  --bg-2: #111827;
  --card: #1e293b;
  --card-soft: #263548;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --primary: #f79724;
  --primary-2: #fbbf24;
  --success: #10b981;
  --info: #06b6d4;
  --danger: #ef4444;
  --shadow: 0 25px 55px rgba(0, 0, 0, .38);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --font: Inter, "Noto Sans Thai", "Sarabun", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; font-family: var(--font); color: var(--text); background: var(--bg); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.auth-body { display: grid; place-items: center; padding: 24px; overflow-x: hidden; position: relative; }
.bg-grid { position: fixed; inset: 0; background-image: linear-gradient(rgba(51,65,85,.34) 1px, transparent 1px), linear-gradient(90deg, rgba(51,65,85,.34) 1px, transparent 1px); background-size: 48px 48px; mask-image: radial-gradient(circle at 50% 50%, black 24%, transparent 78%); pointer-events: none; }
.glow { position: fixed; width: 420px; height: 420px; border-radius: 999px; filter: blur(8px); pointer-events: none; opacity: .85; }
.glow-one { top: -120px; right: -120px; background: radial-gradient(circle, rgba(247,151,36,.23), transparent 66%); }
.glow-two { bottom: -130px; left: -130px; background: radial-gradient(circle, rgba(6,182,212,.14), transparent 66%); }
.auth-wrapper { width: min(100%, 460px); position: relative; z-index: 2; animation: fade-up .62s cubic-bezier(.23,1,.32,1); }
.auth-card { background: linear-gradient(145deg, rgba(30,41,59,.98), rgba(15,23,42,.96)); border: 1px solid rgba(148,163,184,.22); border-radius: 32px; box-shadow: var(--shadow); padding: 38px 34px; }
.auth-header { text-align: center; margin-bottom: 26px; }
.login-logo { width: 62px; height: 62px; border-radius: 20px; margin: 0 auto 18px; display: grid; place-items: center; font-size: 28px; color: #111827; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 18px 28px rgba(247,151,36,.28); }
.eyebrow { margin: 0 0 6px; color: var(--primary); letter-spacing: .14em; text-transform: uppercase; font-size: 11px; font-weight: 800; }
h1, h2, h3, p { margin-top: 0; }
.auth-header h1 { margin-bottom: 8px; font-size: clamp(28px, 5vw, 36px); letter-spacing: -.04em; }
.auth-header p { color: var(--muted); margin-bottom: 0; line-height: 1.65; }
.auth-form, .stack-form { display: grid; gap: 16px; }
.field-group { display: grid; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 700; }
.field-group small { color: var(--muted-2); font-weight: 500; }
.field-control { display: flex; align-items: center; gap: 8px; background: rgba(15,23,42,.9); border: 1px solid var(--line); border-radius: 16px; padding: 0 12px; transition: .2s ease; }
.field-control:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(247,151,36,.15); }
.field-icon { color: var(--muted-2); font-weight: 900; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: rgba(15,23,42,.86); color: var(--text); border-radius: 14px; padding: 13px 14px; outline: 0; transition: .2s ease; }
.field-control input { border: 0; background: transparent; padding: 14px 0; border-radius: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(247,151,36,.14); }
textarea { resize: vertical; min-height: 100px; }
.ghost-btn { border: 0; background: transparent; color: var(--muted); padding: 8px; }
.form-row-between, .button-row, .panel-head, .filter-bar { display: flex; align-items: center; gap: 12px; }
.form-row-between, .panel-head { justify-content: space-between; }
.check-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.check-line input { width: 16px; height: 16px; accent-color: var(--primary); }
.muted-text { color: var(--muted-2); font-size: 13px; }
.primary-btn, .secondary-btn, .small-btn { border: 0; border-radius: 14px; padding: 12px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; transition: .2s ease; }
.primary-btn { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #111827; box-shadow: 0 13px 22px rgba(247,151,36,.25); }
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 16px 28px rgba(247,151,36,.34); }
.secondary-btn { border: 1px solid var(--line); background: rgba(148,163,184,.08); color: var(--text); }
.full-btn { width: 100%; margin-top: 6px; }
.small-btn { padding: 8px 11px; border: 1px solid var(--line); background: rgba(148,163,184,.08); color: var(--text); font-size: 12px; }
.danger-btn { color: #fecaca; border-color: rgba(239,68,68,.3); background: rgba(239,68,68,.1); }
.text-link { color: var(--primary); font-weight: 800; }

.app-body { background: radial-gradient(circle at top right, rgba(247,151,36,.12), transparent 34%), var(--bg); }
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 280px; flex: 0 0 280px; min-height: 100vh; position: sticky; top: 0; background: rgba(15,23,42,.86); border-right: 1px solid var(--line); padding: 22px; display: flex; flex-direction: column; gap: 28px; backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 44px; height: 44px; border-radius: 16px; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #111827; font-weight: 900; font-size: 22px; }
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); margin-top: 2px; }
.side-nav { display: grid; gap: 8px; }
.side-nav a { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 12px 14px; border-radius: 16px; font-weight: 800; }
.side-nav a:hover, .side-nav a.is-active { color: var(--text); background: rgba(247,151,36,.12); box-shadow: inset 0 0 0 1px rgba(247,151,36,.22); }
.sidebar-footer { margin-top: auto; display: grid; gap: 12px; }
.mini-card { padding: 14px; border-radius: 18px; background: rgba(30,41,59,.72); border: 1px solid var(--line); }
.mini-card small, .mini-card strong { display: block; overflow-wrap: anywhere; }
.mini-card small { color: var(--muted); margin-bottom: 4px; }
.logout-link { color: var(--primary); font-weight: 900; padding: 10px 2px; }
.main-content { flex: 1; min-width: 0; padding: 26px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: clamp(24px, 4vw, 34px); letter-spacing: -.035em; }
.topbar-user { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 18px; background: rgba(30,41,59,.62); }
.topbar-user strong, .topbar-user small { display: block; }
.topbar-user small { color: var(--muted); }
.avatar { width: 38px; height: 38px; border-radius: 14px; display: grid; place-items: center; background: rgba(247,151,36,.14); color: var(--primary); border: 1px solid rgba(247,151,36,.28); font-weight: 900; }
.avatar.small { width: 34px; height: 34px; border-radius: 12px; }
.icon-btn { width: 42px; height: 42px; border-radius: 14px; border: 1px solid var(--line); background: rgba(30,41,59,.72); color: var(--text); display: none; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 18px; }
.stat-card, .panel { background: rgba(30,41,59,.78); border: 1px solid rgba(148,163,184,.18); border-radius: 24px; box-shadow: 0 20px 40px rgba(0,0,0,.16); }
.stat-card { padding: 20px; display: grid; gap: 7px; }
.stat-card span { font-size: 26px; }
.stat-card small { color: var(--muted); font-weight: 800; }
.stat-card strong { font-size: 32px; letter-spacing: -.04em; }
.content-grid { display: grid; gap: 18px; }
.two-cols { grid-template-columns: minmax(0,1fr) minmax(320px,.72fr); }
.wide-left { grid-template-columns: minmax(0,1.3fr) minmax(330px,.7fr); }
.panel { padding: 20px; }
.panel h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.sticky-panel { align-self: start; position: sticky; top: 20px; }
.tool-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.tool-card { display: grid; gap: 5px; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: rgba(15,23,42,.48); }
.tool-card:hover { border-color: rgba(247,151,36,.45); transform: translateY(-1px); }
.tool-icon { font-size: 26px; }
.tool-card small { color: var(--muted); }
.timeline-list { display: grid; gap: 14px; }
.timeline-item { display: grid; grid-template-columns: 14px 1fr; gap: 10px; }
.timeline-item .dot { width: 10px; height: 10px; border-radius: 999px; background: var(--primary); margin-top: 6px; box-shadow: 0 0 0 5px rgba(247,151,36,.12); }
.timeline-item p { margin: 3px 0; color: var(--muted); }
.timeline-item small, .data-table small { display: block; color: var(--muted-2); margin-top: 3px; }
.table-wrap { overflow-x: auto; margin-top: 10px; }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.data-table th, .data-table td { padding: 13px 10px; border-bottom: 1px solid rgba(51,65,85,.75); text-align: left; vertical-align: middle; }
.data-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.cell-title { display: flex; gap: 11px; align-items: center; min-width: 250px; }
.cell-title > span:not(.avatar) { font-size: 24px; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 900; border: 1px solid var(--line); color: var(--muted); }
.badge-success { color: #bbf7d0; background: rgba(16,185,129,.1); border-color: rgba(16,185,129,.28); }
.badge-info { color: #cffafe; background: rgba(6,182,212,.1); border-color: rgba(6,182,212,.28); }
.badge-muted { background: rgba(148,163,184,.08); }
.text-right { text-align: right !important; }
.action-cell { white-space: nowrap; }
.inline-form { display: inline-flex; margin-left: 5px; }
.filter-bar { flex-wrap: wrap; margin: 16px 0; }
.filter-bar input { max-width: 420px; }
.filter-bar select { max-width: 190px; }
.info-list { display: grid; gap: 12px; }
.info-list div { display: flex; justify-content: space-between; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: rgba(15,23,42,.42); }
.info-list span { color: var(--muted); }
.soft-line { border: 0; border-top: 1px solid var(--line); width: 100%; }
.alert { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 15px; border-radius: 16px; margin-bottom: 14px; border: 1px solid var(--line); background: rgba(30,41,59,.92); }
.alert button { border: 0; background: transparent; color: inherit; font-size: 20px; }
.alert-success { color: #bbf7d0; border-color: rgba(16,185,129,.28); background: rgba(16,185,129,.10); }
.alert-danger { color: #fecaca; border-color: rgba(239,68,68,.28); background: rgba(239,68,68,.10); }
.alert-warning { color: #fde68a; border-color: rgba(245,158,11,.28); background: rgba(245,158,11,.10); }
.empty-state { color: var(--muted); text-align: center; padding: 26px; }
code { color: #c4b5fd; }

@keyframes fade-up { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .two-cols, .wide-left { grid-template-columns: 1fr; }
  .sticky-panel { position: static; }
}

@media (max-width: 820px) {
  .sidebar { position: fixed; z-index: 40; transform: translateX(-105%); transition: .22s ease; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); backdrop-filter: blur(2px); z-index: 30; opacity: 0; pointer-events: none; transition: .22s ease; }
  .sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .icon-btn { display: grid; place-items: center; }
  .main-content { padding: 18px; }
  .topbar { align-items: flex-start; }
  .hide-mobile { display: none; }
  .tool-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .auth-body { padding: 14px; }
  .auth-card { padding: 28px 20px; border-radius: 26px; }
  .stats-grid { grid-template-columns: 1fr; }
  .panel { padding: 16px; border-radius: 20px; }
  .topbar-user { display: none; }
  .button-row, .form-row-between { align-items: stretch; flex-direction: column; }
  .primary-btn, .secondary-btn { width: 100%; }
}

/* Phase 1.1 — Hub Catalog UI Refresh */
.hub-layout { grid-template-columns: 1fr; }
.hub-catalog-panel { min-height: calc(100vh - 150px); }
.hub-panel-head { align-items: flex-start; }
.panel-subtitle { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.compact-btn { padding: 10px 14px; white-space: nowrap; }
.compact-head { margin-bottom: 14px; }
.inline-editor-panel { margin: 18px 0 22px; padding: 18px; border: 1px solid rgba(247,151,36,.26); border-radius: 22px; background: rgba(15,23,42,.55); box-shadow: inset 0 0 0 1px rgba(255,255,255,.02); }
.tool-inline-form { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.tool-inline-form .wide-field { grid-column: 1 / -1; }
.hub-icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; margin-top: 18px; }
.hub-icon-card { position: relative; min-height: 210px; display: flex; flex-direction: column; justify-content: space-between; gap: 14px; padding: 18px; border: 1px solid rgba(148,163,184,.18); border-radius: 24px; background: linear-gradient(145deg, rgba(15,23,42,.68), rgba(30,41,59,.68)); box-shadow: 0 18px 34px rgba(0,0,0,.16); transition: transform .18s ease, border-color .18s ease, background .18s ease; overflow: hidden; }
.hub-icon-card::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at top right, rgba(247,151,36,.16), transparent 42%); opacity: 0; transition: opacity .18s ease; pointer-events: none; }
.hub-icon-card:hover { transform: translateY(-3px); border-color: rgba(247,151,36,.45); background: linear-gradient(145deg, rgba(15,23,42,.82), rgba(30,41,59,.8)); }
.hub-icon-card:hover::before { opacity: 1; }
.hub-icon-card.is-inactive { opacity: .62; }
.hub-card-main { position: relative; z-index: 1; display: grid; justify-items: center; text-align: center; gap: 12px; }
.hub-card-icon { width: 66px; height: 66px; display: grid; place-items: center; border-radius: 22px; font-size: 34px; background: rgba(247,151,36,.14); border: 1px solid rgba(247,151,36,.28); box-shadow: 0 16px 32px rgba(0,0,0,.16); }
.hub-card-content { display: grid; gap: 6px; min-width: 0; }
.hub-card-content strong { font-size: 17px; letter-spacing: -.015em; overflow-wrap: anywhere; }
.hub-card-content small { color: var(--muted); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hub-card-meta { position: relative; z-index: 1; display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; }
.hub-card-actions { position: relative; z-index: 1; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; padding-top: 2px; }

@media (max-width: 1100px) {
  .tool-inline-form { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 700px) {
  .hub-panel-head { flex-direction: column; }
  .compact-btn { width: 100%; }
  .tool-inline-form { grid-template-columns: 1fr; }
  .hub-icon-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
  .hub-icon-card { min-height: 190px; padding: 14px; border-radius: 20px; }
  .hub-card-icon { width: 56px; height: 56px; border-radius: 18px; font-size: 28px; }
}

@media (max-width: 430px) {
  .hub-icon-grid { grid-template-columns: 1fr; }
}

/* Phase 1.2 — Log Center Refresh */
.log-stats-grid { margin-bottom: 18px; }
.log-head { align-items: flex-start; }
.advanced-filter-bar { display: grid; grid-template-columns: minmax(220px, 1.4fr) repeat(6, minmax(130px, .8fr)); gap: 12px; align-items: end; margin: 18px 0; }
.advanced-filter-bar .field-group { gap: 6px; margin: 0; }
.advanced-filter-bar .field-group span { color: var(--muted); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; }
.advanced-filter-bar input, .advanced-filter-bar select { max-width: none; width: 100%; }
.login-filter-bar { grid-template-columns: minmax(220px, 1.4fr) repeat(4, minmax(130px, .8fr)) minmax(180px, auto); }
.filter-actions { align-self: end; flex-wrap: nowrap; }
.log-table { min-width: 980px; }
.log-table .time-cell { white-space: nowrap; color: var(--muted); font-weight: 800; }
.log-detail-cell { max-width: 520px; }
.ua-line { max-width: 620px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-danger { color: #fecaca; background: rgba(239,68,68,.10); border-color: rgba(239,68,68,.28); }
.table-note { text-align: right; margin-top: 12px; }

@media (max-width: 1180px) {
  .advanced-filter-bar, .login-filter-bar { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .filter-actions { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .advanced-filter-bar, .login-filter-bar { grid-template-columns: 1fr; }
  .log-head { flex-direction: column; }
  .log-head .compact-btn { width: 100%; }
  .filter-actions { flex-direction: column; }
  .table-note { text-align: left; }
}
