* {
  box-sizing: border-box;
}

:root {
  --ink: #2a2a2a;
  --muted: #77706a;
  --line: #ddd5ce;
  --panel: #fbf9f6;
  --panel-strong: #ffffff;
  --mist: #f4efea;
  --sidebar: #f7f2ed;
  --accent: #c86717;
  --accent-strong: #ad5610;
  --accent-soft: #f6e6d7;
  --shadow: 0 10px 24px rgba(78, 52, 30, 0.08);
}

body {
  margin: 0;
  font-family: "Aptos", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #f8f4f0 0%, var(--mist) 100%);
}

button,
input {
  font: inherit;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.portal-shell {
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  height: 100vh;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  color: var(--ink);
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(64, 46, 33, 0.08);
  z-index: 2;
}

.brand-block {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  min-width: 360px;
  height: 100%;
  padding: 0 22px;
  border-right: 1px solid var(--line);
}

.brand-logo {
  display: block;
  width: 46px;
  height: auto;
  object-fit: contain;
}

.brand-copy {
  min-width: 0;
}

.top-left-logo {
  width: 42px;
  justify-self: start;
}

.portal-name {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.current-app {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.top-bar-spacer {
  flex: 1 1 auto;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  padding: 0 22px;
}

.account-menu {
  position: relative;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 0 14px;
  color: var(--accent-strong);
  background: transparent;
  border: 1px solid #f0caa7;
  border-radius: 999px;
  box-shadow: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
}

.user-pill-chevron {
  color: var(--muted);
  font-size: 11px;
}

.account-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 148px;
  padding: 8px;
  background: #fff;
  border: 1px solid #ead8c8;
  border-radius: 14px;
  box-shadow: 0 14px 30px rgba(64, 46, 33, 0.12);
  z-index: 5;
}

.account-dropdown-item {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 0;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.account-dropdown-item:hover {
  background: #f8f2ec;
}

.icon-button,
.ghost-button,
.primary-button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: var(--accent);
  background: rgba(200, 103, 23, 0.1);
}

.ghost-button,
.primary-button {
  padding: 9px 16px;
  font-weight: 600;
}

.ghost-button {
  color: var(--ink);
  background: #f3efeb;
}

.primary-button {
  color: #fff;
  background: var(--accent);
}

.is-active-mode {
  box-shadow: 0 8px 18px rgba(200, 103, 23, 0.22);
}

.top-right-logo {
  width: 46px;
  margin-left: 4px;
}

.workspace {
  display: grid;
  grid-template-columns: 312px minmax(0, 1fr);
  min-height: 0;
}

.rail-collapsed .workspace {
  grid-template-columns: 88px minmax(0, 1fr);
}

.app-rail {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  min-width: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.rail-icon-strip {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 14px 10px;
  background: #f2ebe4;
  border-right: 1px solid var(--line);
}

.rail-title {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
}

.rail-toggle {
  margin: 0 auto;
}

.rail-icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto;
  color: var(--accent);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  font-size: 22px;
}

.rail-icon-button.is-active {
  background: #fff;
  border-color: #ecd4bc;
  box-shadow: 0 4px 12px rgba(120, 76, 38, 0.08);
}

.rail-panel {
  overflow-y: auto;
  padding: 16px 14px;
}

.rail-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}

.rail-group {
  margin-bottom: 10px;
}

.rail-group.is-focused .rail-group-button {
  color: var(--accent);
  background: #fff3e7;
}

.rail-group-button,
.rail-app {
  width: 100%;
  border: 0;
  cursor: pointer;
  text-align: left;
}

.rail-group-button {
  display: flex;
  justify-content: space-between;
  padding: 11px 12px;
  color: var(--ink);
  background: #f4efe9;
  border-radius: 10px;
  font-weight: 600;
}

.rail-group-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.rail-group-glyph {
  color: var(--accent);
  font-size: 18px;
}

.rail-group-toggle {
  color: var(--muted);
}

.rail-apps {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.rail-app {
  display: grid;
  gap: 4px;
  padding: 10px 12px 10px 40px;
  color: var(--ink);
  background: transparent;
  border-radius: 10px;
}

.rail-app small,
.rail-empty {
  color: var(--muted);
  line-height: 1.35;
}

.rail-app.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(200, 103, 23, 0.14);
}

.rail-app.is-active small {
  color: rgba(173, 86, 16, 0.8);
}

.app-rail.is-collapsed {
  grid-template-columns: 72px 0;
}

.app-rail.is-collapsed .rail-panel {
  display: none;
}

.content-area {
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 10px 14px;
}

.content-area-admin {
  align-content: start;
}

.warning-banner {
  align-self: start;
  margin: 0 0 10px;
  padding: 12px 14px;
  color: #78350f;
  background: #fef3c7;
  border: 1px solid #fbbf24;
  border-radius: 10px;
}

.app-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
}

.empty-state {
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.home-panel,
.admin-panel {
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 480px);
  padding: 28px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.auth-card-loading {
  text-align: center;
}

.auth-brand {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.auth-logo {
  width: 56px;
}

.auth-copy {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.auth-submit {
  justify-self: start;
  min-width: 132px;
}

.home-panel {
  display: grid;
  gap: 22px;
  align-content: start;
  min-height: 100%;
  padding: 18px 20px;
}

.home-hero h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 44px);
  letter-spacing: -0.03em;
}

.home-hero p:last-child {
  max-width: 48rem;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.app-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.app-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  align-items: start;
  width: 100%;
  padding: 18px;
  text-align: left;
  background: #fcfaf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: none;
  cursor: pointer;
}

.app-card-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 12px;
  font-size: 18px;
  font-weight: 800;
}

.app-card-group {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-card h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.03em;
}

.app-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.admin-panel {
  padding: 24px;
}

.field-block {
  display: grid;
  gap: 7px;
}

.field-block > span {
  font-size: 13px;
  font-weight: 700;
}

.field-block input {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.field-hint,
.inline-error {
  font-size: 13px;
  line-height: 1.45;
}

.field-hint {
  color: var(--muted);
}

.inline-error {
  color: #991b1b;
}

.admin-heading {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 20px;
}

.admin-heading h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  letter-spacing: -0.04em;
}

.admin-heading p {
  margin: 8px 0 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 4px !important;
  color: var(--accent) !important;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: start;
  justify-content: flex-end;
}

.ghost-panel-button,
.save-button,
.remove-button {
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

.ghost-panel-button {
  padding: 10px 13px;
  color: var(--ink);
  background: #f3efeb;
}

.save-button {
  padding: 10px 15px;
  color: #fff;
  background: var(--accent);
}

.remove-button {
  padding: 8px 10px;
  color: #991b1b;
  background: #fee2e2;
}

.status-banner,
.error-banner {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 10px;
}

.status-banner {
  color: #065f46;
  background: #d1fae5;
}

.error-banner {
  color: #991b1b;
  background: #fee2e2;
}

.settings-panel {
  display: grid;
  gap: 18px;
}

.settings-form {
  display: grid;
  gap: 18px;
}

.settings-section,
.settings-loading-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: #fcfaf8;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.settings-section-header h2,
.settings-loading-card h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.03em;
}

.settings-section-header p,
.settings-loading-card p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.variable-list {
  display: grid;
  gap: 10px;
}

.app-links-list {
  display: grid;
  gap: 14px;
}

.app-link-row {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.app-link-row-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.app-link-row-header strong {
  display: block;
  margin-bottom: 4px;
  font-size: 16px;
}

.toggle-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.toggle-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.app-links-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.app-link-url,
.app-link-description {
  grid-column: 1 / -1;
}

.variable-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(220px, 1.1fr) auto;
  gap: 10px;
  align-items: center;
}

.admin-table {
  display: grid;
  gap: 8px;
  min-width: 1120px;
}

.admin-row {
  display: grid;
  grid-template-columns: 72px 150px 160px 150px minmax(240px, 1fr) 90px minmax(220px, 1fr) 90px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  background: #f8f4ef;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.admin-row-header {
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.admin-row input {
  width: 100%;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toggle-cell {
  display: grid;
  place-items: center;
}

.toggle-cell input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.source-config {
  margin-top: 18px;
  color: var(--muted);
}

.source-config pre {
  overflow: auto;
  padding: 14px;
  color: var(--ink);
  background: #f8f4ef;
  border: 1px solid var(--line);
  border-radius: 10px;
}

@media (max-width: 780px) {
  .top-bar {
    flex-wrap: wrap;
    align-items: stretch;
  }

  .brand-block {
    min-width: 0;
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px 18px;
  }

  .top-bar-spacer {
    display: none;
  }

  .top-bar-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding: 12px 18px;
  }

  .portal-shell,
  .workspace,
  .rail-collapsed .workspace {
    grid-template-columns: 1fr;
  }

  .portal-shell {
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .top-bar {
    flex-wrap: wrap;
    min-height: 64px;
  }

  .brand-block {
    min-width: 0;
    width: 100%;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .top-bar-spacer {
    display: none;
  }

  .top-bar-actions {
    width: 100%;
    justify-content: flex-end;
    padding: 10px 12px;
  }

  .top-right-logo {
    width: 36px;
  }

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

  .app-rail,
  .app-rail.is-collapsed {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rail-icon-strip {
    padding: 12px 8px;
  }

  .rail-panel {
    padding: 12px;
  }

  .content-area {
    min-height: 70vh;
    padding: 8px;
  }

  .auth-shell {
    padding: 16px;
  }

  .auth-card {
    padding: 20px;
    border-radius: 14px;
  }

  .auth-brand {
    grid-template-columns: 1fr;
  }

  .admin-panel,
  .home-panel {
    padding: 16px;
  }

  .app-card {
    grid-template-columns: 48px 1fr;
    padding: 14px;
  }

  .app-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }

  .admin-heading {
    flex-direction: column;
  }

  .app-links-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid,
  .variable-row {
    grid-template-columns: 1fr;
  }
}
