*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: var(--font-ui);
  color: var(--color-text);
  background: var(--surface-page, #f8fafc);
}

button, input, select { font-family: inherit; color: inherit; }

a { color: var(--theme-primary); }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.2s ease;
}

.app-shell.sidebar-collapsed { grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr); }

.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  background: #fff;
  border-right: 1px solid var(--surface-border);
  transition: width 0.2s ease;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  height: var(--header-height);
  padding: 0 1rem;
  border-bottom: 1px solid var(--surface-border);
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--theme-primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: none;
}

.brand-title { font-weight: 700; white-space: nowrap; }

.sidebar.collapsed .brand-title,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .profile-text { display: none; }

.sidebar.collapsed .brand,
.sidebar.collapsed .nav-item,
.sidebar.collapsed .profile { justify-content: center; padding-left: 0; padding-right: 0; }

.nav { display: flex; flex-direction: column; gap: 0.15rem; padding: 0.75rem; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 36px;
  padding: 0 0.7rem;
  border-radius: 9px;
  color: var(--color-text);
  text-decoration: none;
}

.nav-item[aria-current="page"] { background: var(--color-accent-soft); color: var(--theme-primary); }

.nav-item svg { flex: none; }

.sidebar-footer {
  margin-top: auto;
  padding: 0.75rem;
  border-top: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.profile { display: flex; align-items: center; gap: 0.7rem; min-height: 44px; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-accent-soft);
  color: var(--theme-primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: none;
}

.profile-name { font-weight: 700; line-height: 1.2; }
.profile-role { color: var(--color-muted); font-size: 0.85rem; }

.workspace { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

.app-header-atmosphere {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--header-height);
  padding: 0 1.25rem;
  color: #102033;
}

.topbar-left, .header-actions, .tabs { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }

.page-title { margin: 0; font-size: 1.35rem; font-weight: 700; white-space: nowrap; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.icon-button:hover { background: var(--color-accent-soft); }

.icon-button:disabled, .icon-button[aria-disabled="true"] { opacity: 0.35; pointer-events: none; }

.tabs {
  background: #f1f4f8;
  border-radius: 10px;
  padding: 0.2rem;
  gap: 0;
}

.tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 0.85rem;
  border-radius: 8px;
  color: var(--color-text);
  text-decoration: none;
  font-weight: 600;
}

.tabs a[aria-selected="true"] {
  background: #fff;
  box-shadow: 0 2px 6px rgba(20, 30, 50, 0.08);
}

.page {
  flex: 1;
  min-height: 0;
  padding: 1.25rem;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 1rem;
  height: calc(100vh - var(--header-height) - 2.5rem);
}

.panel {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03), 0 8px 24px rgba(15, 23, 42, 0.035);
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem 0.4rem;
}

.panel-head a { font-weight: 700; text-decoration: none; }

.panel-body { overflow: auto; padding: 0.4rem 1rem 1rem; }

.widget-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
}

.widget {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 72px;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: #fff;
  color: var(--color-text);
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03), 0 8px 24px rgba(15, 23, 42, 0.035);
}

a.widget:hover { background: var(--color-accent-soft); }

.widget-idle { opacity: 0.55; }

.widget-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--theme-primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: none;
}

.widget-name { font-weight: 700; }

.stat-value { font-size: 2rem; font-weight: 700; margin: 0.2rem 0; }
.muted { color: var(--color-muted); }

.filter-panel { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-start; margin-bottom: 0.75rem; }

.group-by { width: min(280px, 100%); }

.group-row td { background: #f4f7fb; font-weight: 700; text-align: left; }

.tree-pad { display: inline-block; height: 1px; }

.tree-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-right: 2px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  vertical-align: middle;
}

button.tree-toggle { cursor: pointer; }

button.tree-toggle:hover { background: var(--color-accent-soft); }

.form-grid textarea {
  min-height: 96px;
  border: 1px solid #d5dee8;
  border-radius: 9px;
  padding: 0.55rem 0.75rem;
  font-weight: 400;
  resize: vertical;
}

.checks { display: grid; gap: 0.35rem; max-height: 240px; overflow: auto; border: 1px solid #d5dee8; border-radius: 9px; padding: 0.5rem 0.75rem; }

.checks label { display: flex; gap: 0.45rem; align-items: center; font-weight: 400; }

.filter-panel input {
  width: min(420px, 100%);
  min-height: 36px;
  padding: 0 0.75rem;
  border: 1px solid #d5dee8;
  border-radius: 9px;
  background: #fff;
}

.table-wrap { overflow: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
}

table.data th, table.data td {
  font-family: var(--font-table);
  text-align: center;
  vertical-align: middle;
  padding: 0.2rem 0.55rem;
  border-bottom: 1px solid #e6edf4;
}

table.data th {
  font-family: var(--font-table-head);
  font-weight: 600;
  background: #fff;
  position: sticky;
  top: 0;
}

.sort-button {
  font-family: inherit;
  font-weight: 600;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  width: 100%;
}

th.table-align-left .sort-button { text-align: left; }

table.data td.table-align-left, table.data th.table-align-left { text-align: left; }

table.data a.name-link { color: inherit; font-weight: 500; text-decoration: none; }
table.data a.name-link:hover { text-decoration: underline; }

.table-row-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  min-height: 32px;
}

.table-row-actions .icon-button { width: 28px; height: 28px; color: var(--color-text); }

.badge {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 6px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-success { background: #f0fff4; border-color: #9ae6b4; }
.badge-warn { background: #fffff0; border-color: #f6e05e; }
.badge-cancel { background: #fafafa; border-color: #e2e8f0; }
.badge-error { background: #fff5f5; border-color: #fc8181; }

.card-tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; }

.card-tabs a {
  text-decoration: none;
  color: var(--color-text);
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  font-weight: 700;
}

.card-tabs a[aria-selected="true"] { background: var(--color-accent-soft); color: var(--theme-primary); }

.fields { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 0.65rem 1rem; align-items: center; }

.fields dt { color: var(--color-muted); }
.fields dd { margin: 0; }

.form-grid { display: grid; gap: 0.85rem; max-width: 560px; }

.form-grid label { display: grid; gap: 0.3rem; font-weight: 700; }

.form-grid input, .listbox-trigger {
  min-height: 36px;
  border: 1px solid #d5dee8;
  border-radius: 9px;
  background: #fff;
  padding: 0 0.75rem;
  font-weight: 400;
  text-align: left;
}

.listbox { position: relative; }

.listbox-panel {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #d5dee8;
  border-radius: 9px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  padding: 0.25rem;
}

.listbox-panel button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  min-height: 32px;
  border-radius: 7px;
  cursor: pointer;
}

.listbox-panel button[aria-selected="true"], .listbox-panel button:hover { background: var(--color-accent-soft); }

.form-error { color: #9b2c2c; font-weight: 400; }

.hint { color: var(--color-muted); font-weight: 400; font-size: 0.92rem; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 32, 51, 0.28);
  z-index: 20;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 21;
  width: min(420px, 100%);
  height: 100%;
  background: #fff;
  box-shadow: -8px 0 24px rgba(15, 23, 42, 0.08);
  padding: 1rem 1.1rem;
  overflow: auto;
}

.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }

.day-title { margin: 0.8rem 0 0.3rem; font-size: 0.95rem; }

.update-row { display: flex; gap: 0.45rem; align-items: flex-start; padding: 0.35rem 0; }

.update-row button.linkish {
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font-weight: 700;
}

.cogs { display: inline-flex; gap: 1px; color: var(--theme-primary); flex: none; margin-top: 0.15rem; }

.user-access, .theme-panel { padding: 1rem 1.1rem 1.2rem; }

.user-access fieldset {
  border: 1px solid #d5dee8;
  border-radius: 12px;
  margin: 0 0 0.9rem;
  padding: 0.75rem 1rem 0.9rem;
}

.user-access legend { padding: 0 0.3rem; font-weight: 700; }

.user-access label { display: flex; align-items: center; gap: 0.55rem; min-height: 32px; }

.theme-grid { display: grid; grid-template-columns: minmax(260px, 380px) minmax(0, 1fr); gap: 1.25rem; }

.theme-field { margin: 0.75rem 0; }

.theme-field label { display: grid; gap: 0.35rem; font-weight: 700; }

.theme-inputs { display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 0.6rem; align-items: center; }

.theme-inputs input[type="color"] { width: 46px; height: 36px; padding: 0; border: 0; background: none; }

.theme-inputs input[type="text"] {
  min-height: 36px;
  padding: 0 0.7rem;
  border: 1px solid #d5dee8;
  border-radius: 9px;
  font-weight: 400;
}

.theme-toggle { font-weight: 400; display: flex; align-items: center; gap: 0.45rem; margin-top: 0.35rem; }

.theme-note { color: #8a6d1d; min-height: 1.2rem; }

.theme-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; }

.text-button {
  min-height: 36px;
  padding: 0 0.85rem;
  border: 1px solid #d5dee8;
  border-radius: 9px;
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}

.text-button-primary { background: var(--theme-primary); color: #fff; border-color: transparent; }

.text-button:disabled { opacity: 0.45; cursor: default; }

.theme-preview { border: 1px solid var(--surface-border); border-radius: 14px; overflow: hidden; }

.theme-preview-header { min-height: 64px; padding: 0 1rem; font-weight: 700; }

.theme-preview-page { min-height: 220px; padding: 1rem; }

.theme-preview-page .data-surface { padding: 0.6rem 0.8rem; }

.swatches { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; }

.swatch { height: 72px; border-radius: 12px; border: 1px solid var(--surface-border); }

.swatch span { display: block; margin-top: 0.4rem; font-size: 0.85rem; }

.mobile-drawer .sidebar {
  position: fixed;
  z-index: 30;
  top: 0;
  left: 0;
  height: 100%;
  transform: translateX(-105%);
  transition: transform 0.2s ease;
}

.mobile-drawer.drawer-open .sidebar { transform: translateX(0); }

.sidebar-toggle-mobile { display: none; }

@media (max-width: 1024px) {
  .app-shell, .app-shell.sidebar-collapsed { grid-template-columns: 1fr; }
  .sidebar-toggle-desktop { display: none; }
  .sidebar-toggle-mobile { display: inline-flex; }
  .home-grid { grid-template-columns: 1fr; height: auto; }
  .home-grid .panel { min-height: calc(100vh - var(--header-height) - 2.5rem); }
}

@media (max-width: 720px) {
  .fields, .theme-grid { grid-template-columns: 1fr; }
  .swatches { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell, .sidebar, .mobile-drawer .sidebar { transition: none; }
}
