:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --border: #dedede;
  --border-strong: #c9c9c9;
  --text: #444444;
  --text-muted: #777777;
  --text-soft: #999999;
  --link: #4f91d9;
  --primary: #ff6b35;
  --primary-hover: #e85a27;
  --primary-soft: #fff3ec;
  --success: #63b85c;
  --success-soft: #f0f9ee;
  --danger: #c9302c;
  --danger-soft: #fdf1f0;
  --warning: #d97706;
  --warning-soft: #fff8e8;
  --sidebar-bg: #2b3a4b;
  --sidebar-text: #c6cfda;
  --sidebar-text-active: #ffffff;
  --sidebar-hover: #344557;
  --sidebar-active: #38495c;
  --header-bg: #4b555e;
  --header-text: #ffffff;
  --icon-blue: #3b6fb5;
  --icon-navy: #34495e;
  --icon-gray: #7f8c8d;
  --radius: 4px;
  --radius-sm: 3px;
  --shadow: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 2px 6px rgba(0,0,0,0.08);
  --sidebar-width: 260px;
  --rail-width: 280px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 500; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 3px; border: 1px solid var(--border); }

.icon { vertical-align: middle; display: inline-block; flex-shrink: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  font-size: 13px; font-weight: 500; line-height: 1;
  background: var(--surface); color: var(--text);
  transition: background 0.12s, border-color 0.12s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b52725; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

.inline-form { display: inline; }

.btn[aria-disabled="true"] { opacity: 0.65; cursor: wait; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 120; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }
.field-error { color: #b91c1c; font-size: 13px; margin: 6px 0 0; }
[aria-invalid="true"] { border-color: var(--danger); }
[id] { scroll-margin-top: 120px; }

/* ---------- Auth shell ---------- */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2b3a4b 0%, #4b555e 60%, #6b4a2f 100%);
  padding: 24px;
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 32px;
  box-shadow: var(--shadow-md);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.brand-mark-lg { color: var(--primary); }
.auth-brand-name { font-size: 18px; font-weight: 600; }
.auth-title { font-size: 22px; font-weight: 300; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-muted); margin: 0 0 20px; }
.auth-switch { margin-top: 16px; text-align: center; font-size: 13px; color: var(--text-muted); }
.auth-center { text-align: center; }
.error-code { font-size: 52px; font-weight: 800; color: var(--primary); margin-bottom: 8px; }
.error-trace {
  text-align: left; font-family: var(--mono); font-size: 12px;
  background: var(--surface-2); padding: 14px; border-radius: 4px;
  overflow: auto; max-height: 300px; white-space: pre-wrap; margin: 16px 0;
  border: 1px solid var(--border);
}

/* ---------- Shell layout ---------- */
.shell { display: flex; min-height: 100vh; }

/* ---- Top header bar ---- */
.topbar {
  display: flex; align-items: center; gap: 0;
  height: 58px; background: var(--header-bg); color: var(--header-text);
  position: sticky; top: 0; z-index: 60;
}
.topbar-brand {
  height: 58px; width: 220px; flex-shrink: 0;
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: #2b3a4b; color: #fff;
}
.topbar-brand .brand-mark { color: var(--primary); }
.topbar-brand-name { font-size: 16px; font-weight: 600; color: #fff; }
.topbar-menu { display: none; background: none; border: 0; cursor: pointer; color: #fff; padding: 0 14px; height: 58px; }
.topbar-title { font-size: 15px; font-weight: 300; padding: 0 4px; color: rgba(255,255,255,0.9); }
.topbar-actions {
  margin-left: auto; display: flex; align-items: stretch; height: 58px;
}
.topbar-actions .topbar-icon {
  width: 58px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-left: 1px solid rgba(255,255,255,0.18);
  color: #fff; cursor: pointer; position: relative;
}
.topbar-actions .topbar-icon:hover { background: rgba(0,0,0,0.18); }
.topbar-actions .topbar-icon.logout-link { width: auto; padding: 0 16px; gap: 8px; font-size: 13px; text-decoration: none; color: #fff; }
.user-menu { display: flex; align-items: center; gap: 10px; height: 58px; padding: 0 16px; border-left: 1px solid rgba(255,255,255,0.18); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.user-name { font-size: 13px; font-weight: 500; color: #fff; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width); flex-shrink: 0;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-light {
  background: #f0f2f4; color: #3a4a5a;
  border-right: 1px solid var(--border);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-light .sidebar-brand { border-bottom-color: var(--border); }
.brand-mark { color: var(--primary); }
.brand-name { font-size: 14px; font-weight: 600; color: #fff; }
.sidebar-light .brand-name { color: #3a4a5a; }
.sidebar-close { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; display: none; }

.sidebar-search { padding: 12px; position: relative; }
.search-icon { position: absolute; left: 22px; top: 50%; transform: translateY(-50%); color: var(--text-soft); }
.sidebar-search input {
  width: 100%; padding: 8px 10px 8px 34px; border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.12); background: rgba(255,255,255,0.06);
  color: #fff; font-size: 13px;
}
.sidebar-light .sidebar-search input { border-color: var(--border); background: var(--surface); color: var(--text); }
.sidebar-search input::placeholder { color: var(--text-soft); }
.sidebar-search input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.sidebar-nav { flex: 1; padding: 8px; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 11px; color: var(--text-soft); }
.sidebar-light .sidebar-footer { border-top-color: var(--border); }

/* ---------- Nav ---------- */
.nav { list-style: none; margin: 0; padding: 0; }
.nav li { margin: 0; }
.nav-group { position: relative; }

.nav-link, .nav-group-toggle {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: inherit; background: none; border: 0; cursor: pointer;
  font-size: 13px; font-weight: 500; text-align: left;
  position: relative;
}
.nav-link:hover, .nav-group-toggle:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.sidebar-light .nav-link:hover, .sidebar-light .nav-group-toggle:hover { background: #e3e7ea; color: #3a4a5a; }
.nav-link.is-active, .nav-group.is-active > .nav-group-toggle { background: var(--sidebar-active); color: #fff; }
.nav-link.is-active::before, .nav-group.is-active > .nav-group-toggle::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px;
  background: var(--primary); border-radius: 0 2px 2px 0;
}
.sidebar-light .nav-link.is-active, .sidebar-light .nav-group.is-active > .nav-group-toggle { background: #fff; color: #2b3a4b; }
.nav-icon { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; flex-shrink: 0; color: var(--text-soft); }
.nav-icon .icon { width: 100%; height: 100%; }
.sidebar-light .nav-icon { color: #7f8c8d; }
.nav-link.is-active .nav-icon { color: #fff; }
.sidebar-light .nav-link.is-active .nav-icon { color: var(--primary); }
.nav-label { flex: 1; }
.nav-chevron { display: inline-flex; transition: transform 0.15s; color: var(--text-soft); }
.nav-group.is-open .nav-chevron { transform: rotate(180deg); }

.nav-children { list-style: none; margin: 0 0 4px; padding: 0 0 0 16px; display: none; }
.nav-group.is-open .nav-children { display: block; }
.nav-child {
  display: block; padding: 6px 10px 6px 30px; border-radius: var(--radius-sm);
  color: inherit; font-size: 13px; border-left: 2px solid transparent;
}
.nav-child:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.sidebar-light .nav-child:hover { background: #e3e7ea; color: #3a4a5a; }
.nav-child.is-active { border-left-color: var(--primary); color: #fff; background: rgba(255,107,53,0.2); }
.sidebar-light .nav-child.is-active { color: var(--primary); background: #fff; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.content-wrap { flex: 1; display: flex; gap: 0; max-width: 1400px; width: 100%; margin: 0 auto; }
.content { flex: 1; min-width: 0; padding: 24px; }

/* ----- Breadcrumbs ribbon (sub-header) ----- */
.breadcrumbs {
  font-size: 13px; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 8px 16px;
}
.breadcrumbs ol { list-style: none; display: flex; margin: 0; padding: 0; gap: 6px; }
.breadcrumbs li { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.breadcrumbs li + li::before { content: "/"; color: var(--text-soft); }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--link); }

.page-head { margin-bottom: 16px; }
.page-title { font-size: 20px; font-weight: 400; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 24px 0 10px; }

/* ---------- Flash ---------- */
.flash { padding: 11px 14px; border: 1px solid; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13px; }
.flash-success { background: var(--success-soft); color: #2b4a22; border-color: #bfe2b5; }
.flash-error { background: var(--danger-soft); color: #7a1f1c; border-color: #e7b3b1; }
.flash-list { margin: 0; padding-left: 18px; }

/* ---------- Stats ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-value { display: block; font-size: 24px; font-weight: 400; color: var(--text); }
.stat-label { display: block; color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ---------- Cards ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.card-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
.card-value { font-size: 15px; font-weight: 500; margin-top: 4px; }

/* ---- Progress bars ---- */
.bar { height: 6px; background: #e6e6e6; border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 3px; }
.bar-fill.green { background: var(--success); }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th { background: var(--surface-2); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafafa; }
.table .empty { text-align: center; color: var(--text-muted); padding: 28px; }
.table-info th { width: 220px; background: var(--surface-2); font-weight: 500; color: var(--text-muted); }
.nowrap { white-space: nowrap; }
.actions { white-space: nowrap; text-align: right; }
.actions .btn { margin-left: 4px; }
.text-muted { color: var(--text-muted); }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.inherit-link { color: inherit; text-decoration: none; }
.row-unread { font-weight: 600; }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; }
.panel-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-title { font-size: 15px; font-weight: 500; }

/* ---------- Badges & status ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }
.badge-warning { background: var(--warning-soft); border-color: #f2d79a; color: #8a5b00; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-soft); }
.status-active { color: var(--success); }
.status-active::before { background: var(--success); }
.status-disabled { color: var(--text-muted); }
.status-disabled::before { background: var(--text-soft); }
.status-failed { color: var(--danger); }
.status-failed::before { background: var(--danger); }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: flex-end; }
.filter-bar .input { min-width: 180px; }

/* ---------- Forms ---------- */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--text); }
.input {
  padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; color: var(--text); background: var(--surface);
}
.input:focus { outline: 1px solid var(--primary); border-color: var(--primary); }
.input:disabled { background: var(--surface-2); color: var(--text-muted); }
select.input { background: var(--surface); }
.field-help { margin: 0; font-size: 12px; color: var(--text-muted); }
.form-actions { display: flex; gap: 8px; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin: 0; }
.fieldset-legend { font-size: 13px; font-weight: 600; padding: 0 6px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* ---------- Feature grid (customer, cPanel-style) ---------- */
.welcome { margin-bottom: 16px; }
.welcome-title { font-size: 20px; font-weight: 300; }
.welcome-sub { color: var(--text-muted); margin: 2px 0 0; }

.fn-search {
  position: relative; margin: 0 0 20px; max-width: 720px;
}
.fn-search input {
  width: 100%; height: 48px; padding: 0 44px 0 14px;
  font-size: 15px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
.fn-search .search-icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-soft); }
.fn-search input::placeholder { color: var(--text-soft); }

.fn-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.fn-section-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.fn-section-title { font-size: 17px; font-weight: 400; color: var(--text); }

.feature-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; }
.feature {
  display: flex; align-items: center; gap: 12px;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 14px 16px; min-height: 66px;
  color: var(--text); text-decoration: none; background: var(--surface);
}
.feature:hover { background: #fafafa; text-decoration: none; }
.feature-icon { color: var(--icon-blue); }
.feature-label { font-size: 14px; color: var(--link); font-weight: 400; }
.feature:hover .feature-label { text-decoration: underline; }
.feature-links { display: flex; flex-direction: column; gap: 2px; font-size: 13px; margin-left: 34px; }
.feature-links a { color: var(--link); }

/* ---------- Info / stats rail (right column) ---------- */
.rail { width: var(--rail-width); flex-shrink: 0; padding: 24px 16px 24px 0; }
.rail-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.rail-card-header { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; font-weight: 500; }
.rail-row { padding: 10px 16px; border-bottom: 1px solid #eee; }
.rail-row:last-child { border-bottom: 0; }
.rail-row-label { font-weight: 600; font-size: 12px; color: var(--text); }
.rail-row-value { font-size: 13px; color: var(--text-muted); margin-top: 1px; word-break: break-all; }
.rail-stat { padding: 10px 16px; border-bottom: 1px solid #eee; }
.rail-stat:last-child { border-bottom: 0; }

/* ---------- Webmail message ---------- */
.webmail-shell { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; align-items: start; }
.webmail-shell > * { min-width: 0; }
.folder-list { list-style: none; margin: 0; padding: 8px 0; }
.folder-link { display: flex; justify-content: space-between; padding: 6px 14px; color: inherit; text-decoration: none; }
.folder-link:hover { background: var(--surface-2); text-decoration: none; }
.folder-link.active { background: var(--primary-soft); color: var(--primary); }
.message-meta { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.message-meta > div { margin-bottom: 4px; }
.message-meta > div:last-child { margin-bottom: 0; }
.message-body { padding: 16px; }
.message-text { white-space: pre-wrap; word-break: break-word; font-family: inherit; }
.message-attachments { padding: 12px 16px; border-top: 1px solid var(--border); }
.attachment-list { margin: 0; padding: 0; list-style: none; }
.attachment-list li { padding: 4px 0; }

/* ---------- Layout helpers ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.fm-form { display: flex; gap: 6px; align-items: flex-end; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .feature-grid { grid-template-columns: repeat(3, 1fr); }
  .rail { display: none; }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 90; visibility: hidden; transform: translateX(-100%); transition: transform 0.2s; overscroll-behavior: contain; height: 100vh; }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .sidebar { visibility: visible; transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 80; }
  .topbar-menu { display: inline-flex; }
  .topbar-brand { width: auto; flex: 1; }
  .user-name { display: none; }
}
@media (max-width: 700px) {
  .feature-grid { grid-template-columns: repeat(2, 1fr); }
  .webmail-shell { grid-template-columns: minmax(0, 1fr); }
  .content { padding: 16px; }
  .topbar { padding: 0; }
  .topbar-actions .topbar-icon { display: none; }
  .topbar-brand { width: auto; }
  .breadcrumbs ol, .panel-header, .form-actions { flex-wrap: wrap; }
  .btn, .topbar-menu, .sidebar-close { min-height: 44px; }
}
@media (max-width: 460px) {
  .feature-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-chevron, .btn, .feature { transition: none; }
}