/* =========================================================
   BASE UI
   Foundational UI elements for business sites and apps
   ========================================================= */

/* ---------------------------------------------------------
   Global Reset / Defaults
   --------------------------------------------------------- */

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

html {
  font-size: 16px;
}

/* ---------------------------------------------------------
   Typography – Base Application
   --------------------------------------------------------- */
body {
  font-family: var(--font-body);
  font-weight: 500;
}

h1 {
  font-family: var(--font-heading);
  font-weight: 700;
}

h2 {
  font-family: var(--font-heading);
  font-weight: 600;
}

h3 {
  font-family: var(--font-heading);
  font-weight: 500;
}

h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 400;
}


body {
  margin: 0;
  background-color: var(--color-bg-page);
  color: var(--color-text-primary);
  line-height: 1.5;
}

:root {
  --icon-bullet-default: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Ccircle cx='4' cy='4' r='3' fill='black'/%3E%3C/svg%3E");
}


:root {
  --icon-check: url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'>\
<path d='M6.1 11.2L2.9 8l1.4-1.4 1.8 1.8 5-5L12.5 4z' />\
</svg>");
}

:root {
  --icon-warning: url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'>\
<path d='M8 1L15 14H1L8 1z' />\
</svg>");
}

:root {
  --icon-arrow: url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'>\
<path d='M5 3l5 5-5 5' />\
</svg>");
}


/* ---------------------------------------------------------
   Typography
   --------------------------------------------------------- */

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0 0 0.5rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

p {
  margin: 0 0 1rem;
  color: var(--color-text-secondary);
}

small {
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------
   Links
   --------------------------------------------------------- */

a {
  color: var(--color-accent);
  text-decoration: underline;
  text-decoration-thickness: 0.5px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--color-accent-hover);
  text-decoration-thickness: 2px;
}

a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-focus-ring);
}

/* ---------------------------------------------------------
   Buttons
   --------------------------------------------------------- */

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 0.25rem 0.875rem;
  border-radius: 0.375rem;

  font: inherit;
  font-weight: 500;

  border: 1px solid transparent;
  background: none;

  cursor: pointer;
  user-select: none;
}

button:focus-visible,
.button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-focus-ring);
}

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

.button, .btn-plan, .nav-cta {
  text-decoration: none;
}

/* Primary */

.button-primary {
  background-color: var(--color-accent);
  color: var(--color-text-inverse);
}

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

/* Secondary */

.button-secondary {
  background-color: var(--color-bg-surface);
  color: var(--color-text-primary);
  border-color: var(--color-border-default);
}

.button-secondary:hover {
  background-color: var(--color-bg-hover);
}

/* Danger */

.button-danger {
  background-color: var(--color-danger);
  color: var(--color-text-inverse);
}

.button-danger:hover {
  filter: brightness(0.95);
}

.button-primary:hover,
.button-primary:focus-visible {
  color: var(--color-text-inverse);
  text-decoration: none;
}

.button-secondary:hover,
.button-secondary:focus-visible {
  color: var(--color-text-primary);
  text-decoration: none;
}

.button-danger:hover,
.button-danger:focus-visible {
  color: var(--color-text-inverse);
  text-decoration: none;
}



/* ---------------------------------------------------------
   Lists
   --------------------------------------------------------- */

ul,
ol {
  padding-left: 1.25rem;
  margin: 0 0 1rem;
}

li {
  margin: 0.25rem 0;
}

/* UI List */

.list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.list-item {
  padding: 0;
  border-radius: 0.375rem;
  cursor: pointer;
}

.list-item > a {
  display: block;
  width: 100%;
  height: 100%;

  padding: 0.5rem 0.75rem;
  color: inherit;
  text-decoration: none;
}


.list-item:hover {
  background-color: var(--color-bg-hover);
}

.list-item.active {
  background-color: var(--color-bg-active);
  font-weight: 500;
}

.list-item > a:hover,
.list-item > a:focus-visible {
  text-decoration: none;
}

.list-item > a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-focus-ring);
}



/* ---------------------------------------------------------
   Panels / Cards
   --------------------------------------------------------- */

.panel {
  background-color: var(--color-bg-surface);
  border: 1px solid var(--color-border-default);
  border-radius: 0.5rem;
  padding: 1rem;
}

.panel-header {
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.panel-footer {
  margin-top: 0.75rem;
  color: var(--color-text-muted);
}

.panel + .panel {
  margin-top: 1rem;
}

/* ---------------------------------------------------------
   Sections
   --------------------------------------------------------- */

.section {
  margin-top: 2rem;
}

.section:first-child {
  margin-top: 0;
}

.section .panel + .panel {
  margin-top: 0.75rem;
}

/* ---------------------------------------------------------
   Layout Helpers
   --------------------------------------------------------- */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */

.sidebar {
  width: 240px;
  background-color: var(--color-bg-surface);
  border-right: 1px solid var(--color-border-default);
  padding: 1rem;

  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}


.sidebar-title {
  margin-bottom: 1rem;
  font-weight: 600;
  margin-top: 1rem;
}

.sidebar .list-item {
  margin-bottom: 0.25rem;
}

/* ---------------------------------------------------------
   Header
   --------------------------------------------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;

  padding: 5px 10px;

  background-color: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border-default);
  
  overflow: visible;
}

.app-header-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--color-text-primary);
}

.app-header-left {
	display: inline-flex;
	align-items: center;
}

.app-header-actions {
  display: flex;
  gap: 0.5rem;
}

.app-header a,
.nav-links a {
  text-decoration: none;
}

/* ---------------------------------------------------------
   Sticky Header (Mobile)
   --------------------------------------------------------- */

@media (max-width: 768px) {
  .app-header {
    position: sticky;
    top: 0;
    z-index: 1100;
  }
}


/* ---------------------------------------------------------
   Footer
   --------------------------------------------------------- */

.app-footer {
  padding: 1rem 1.25rem;
  margin-top: auto;
  background-color: var(--color-bg-page);
  border-top: 1px solid var(--color-border-subtle);
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}



/* ---------------------------------------------------------
   Horizontal Navigation
   --------------------------------------------------------- */

.nav-horizontal {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-horizontal a {
  padding: 2px 10px;
  color: var(--color-text-secondary);
  text-decoration: none;
  font-weight: 500;
}

.nav-horizontal a:hover {
  color: var(--color-text-primary);
}

.nav-horizontal a.active {
  color: var(--color-text-primary);
  border-bottom: 1px solid var(--color-accent);
}

/* ---------------------------------------------------------
   Mobile Navigation
   --------------------------------------------------------- */

.nav-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--color-text-primary);
}

/* Mobile breakpoint */
@media (max-width: 768px) {
  .nav-horizontal {
    display: none;
  }

  .nav-horizontal.nav-open {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding-top: 0.5rem;
  }

  .nav-horizontal a {
    padding: 0.75rem 0;
  }

  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ---------------------------------------------------------
   Responsive Sidebar
   --------------------------------------------------------- */

@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;

    height: 100vh;
    width: 260px;

    transform: translateX(-100%);
    transition: transform 0.2s ease-in-out;

    z-index: 1000;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  }

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

  .main {
    padding: 1rem;
  }
}

/* ---------------------------------------------------------
   Sidebar Backdrop (Mobile)
   --------------------------------------------------------- */

@media (max-width: 768px) {
  .sidebar-backdrop {
    display: none;
  }

  .sidebar.is-open + .sidebar-backdrop {
    display: block;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
  }
}


/* Main Content */

.main {
  flex: 1;
  padding: 10px;
  background-color: var(--color-bg-page);
}

/* ---------------------------------------------------------
   Tables (Business Default)
   --------------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--color-bg-surface);
}

th,
td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border-subtle);
}

th {
  font-weight: 600;
  color: var(--color-text-secondary);
}

tr:hover td {
  background-color: var(--color-bg-hover);
}

table .button {
  min-width: 7rem;
  justify-content: center;
}


/* ---------------------------------------------------------
   Utility
   --------------------------------------------------------- */

.hidden {
  display: none;
}

.text-muted {
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------
   Heading spacing
   --------------------------------------------------------- */

h1,
h2,
h3,
h4,
h5,
h6 {
  margin-top: 0;
  margin-bottom: 0.75rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

h1 {
  margin-bottom: 1rem;
}

h2 {
  margin-bottom: 0.875rem;
}

p + h1,
p + h2,
p + h3,
p + h4,
p + h5,
p + h6,
ul + h1,
ul + h2,
ul + h3,
ul + h4,
ul + h5,
ul + h6,
ol + h1,
ol + h2,
ol + h3,
ol + h4,
ol + h5,
ol + h6 {
  margin-top: 1.25rem;
}

/* ---------------------------------------------------------
   Content Lists (icon-based bullets)
   --------------------------------------------------------- */

ul {
  list-style: none;
  padding-left: 0;
  margin: 0 0 1rem;
}

ul li {
  position: relative;
  padding-left: 1.75rem;
  margin: 0.375rem 0;
}


ul li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);

  width: 0.875rem;
  height: 0.875rem;

  background-color: var(--list-bullet-color, var(--color-text-muted));

  mask-image: var(--list-bullet-icon, var(--icon-bullet-default));
  mask-repeat: no-repeat;
  mask-position: center;
  mask-size: contain;

  -webkit-mask-image: var(--list-bullet-icon, var(--icon-bullet-default));
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  -webkit-mask-size: contain;
}



ul ul {
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

ul ul li {
  margin: 0.25rem 0;
}

/* Custom list variants */

.list-check li::before {
  --list-bullet-icon: var(--icon-check);
  --list-bullet-color: var(--color-success);
}

.list-warning li::before {
  --list-bullet-icon: var(--icon-warning);
  --list-bullet-color: var(--color-warning);
}

.list-arrow li::before {
  --list-bullet-icon: var(--icon-arrow);
}


/* ---------------------------------------------------------
   UI Lists (navigation, menus)
   --------------------------------------------------------- */

.list,
.list ul {
  list-style: none;
  padding-left: 0;
}

.list-item {
  padding-left: 0;
}

.list-item::before {
  content: none;
}

/* ---------------------------------------------------------
   Selectable Content Lists
   --------------------------------------------------------- */

.list-selectable {
  list-style: none;
  padding: 0px 5px;
  margin: 0 0 1rem;
  border: 1px solid var(--color-border-default);
  border-radius: 0.5rem;
  overflow: hidden;
}

.list-selectable li {
  position: relative;
  padding: 0.25rem 1rem 0.25rem 2.25rem;
  cursor: pointer;
  background-color: var(--color-bg-surface);
  padding-left: 2.5rem;
}

.list-selectable li:nth-child(even) {
  background-color: var(--color-bg-hover);
}

.list-selectable li:hover {
  background-color: var(--color-bg-active);
}

.list-selectable li:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--color-focus-ring);
}

.list-selectable li.selected {
  background-color: var(--color-bg-active);
  font-weight: 500;
}

.list-selectable li.selected::before {
  --list-bullet-color: var(--color-accent);
}

.list-selectable li > a {
  color: inherit;
  text-decoration: none;
  display: block;
}

.list-selectable li > a:hover {
  text-decoration: none;
}

/* ---------------------------------------------------------
   Plain Content Lists (no bullets)
   --------------------------------------------------------- */

.list-plain {
  list-style: none;
  padding-left: 0;
  margin: 0 0 1rem;
}

.list-plain li {
  padding-left: 0;
  margin: 0.375rem 0;
}

.list-plain li::before {
  content: none;
}


/* ---------------------------------------------------------
   Inline Code
   --------------------------------------------------------- */

code {
  font-family: var(--font-monospace);
  font-weight: 500;
  font-size: 0.875em;

  padding: 0.15em 0.35em;
  border-radius: 0.25rem;

  background-color: var(--color-bg-subtle);
  color: var(--color-text-primary);
}

/* ---------------------------------------------------------
   Code Blocks
   --------------------------------------------------------- */

pre {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;

  background-color: var(--color-bg-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: 0.5rem;

  overflow-x: auto;
}

pre code {
  padding: 0;
  background: none;
  color: var(--color-text-primary);

  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre;
}

/* ---------------------------------------------------------
   Keyboard Input
   --------------------------------------------------------- */

kbd {
  font-family: var(--font-monospace);
  font-weight: 500;
  font-size: 0.85em;

  padding: 0.15em 0.4em;
  border-radius: 0.25rem;

  background-color: var(--color-bg-surface);
  border: 1px solid var(--color-border-default);
  color: var(--color-text-primary);

  box-shadow: inset 0 -1px 0 var(--color-border-subtle);
}


/* ---------------------------------------------------------
   Sample Output
   --------------------------------------------------------- */

samp {
  font-family: var(--font-monospace);
  font-weight: 500;
  font-size: 0.875em;
  color: var(--color-text-secondary);
}

a code {
  text-decoration: none;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.grid .panel {
  margin-top: 0;
}

/* Panels inside grids must not use flow margins */
.grid .panel + .panel {
  margin-top: 0;
}


@media (min-width: 980px) {
  .grid {
	grid-template-columns: 1fr 1fr;
  }
}

/* ---------------------------------------------------------
   Theme Toggle
   --------------------------------------------------------- */

.theme-toggle {
  display: inline-flex;
  gap: 0.25rem;
}

.theme-toggle button {
  border: 0px solid var(--color-border-default);
  background: var(--color-bg-surface);
  color: var(--color-text-primary);

  padding: 2px 5px;
  border-radius: 0.375rem;
  cursor: pointer;
}

.theme-toggle button.active {
  background: var(--color-bg-hover);
  font-weight: 600;
}

/* ---------------------------------------------------------
   Scrollbars
   Subtle, theme-aware normalization
   --------------------------------------------------------- */

/* WebKit-based browsers (Chrome, Edge, Safari) */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--color-bg-surface);
}

::-webkit-scrollbar-thumb {
  background-color: var(--color-border-default);
  border-radius: 8px;
  border: 2px solid var(--color-bg-surface);
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-muted);
}

/* Firefox */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-default) var(--color-bg-surface);
}

/* scrollbars slightly quieter on the page body but normal elsewhere: */

body::-webkit-scrollbar-thumb {
  background-color: var(--color-border-subtle);
}


.has-tooltip {
  position: relative;
}


.has-tooltip::after {
  content: attr(data-title);
  position: absolute;
  transform: translateX(-50%);

  top: auto;
  margin-top: 8px;

  padding: 4px 8px;
  font-size: 12px;
  white-space: normal;
  overflow-wrap: break-word;
  max-width: 200px;

  background: var(--tooltip-bg, #000);
  color: var(--tooltip-fg, #fff);
  border-radius: 4px;

  opacity: 0;
  pointer-events: none;

  transition: opacity 120ms ease;
  z-index: 1000;
  
  max-inline-size: calc(100vw - 16px);
}



/* Default show above */
.has-tooltip:hover::after,
.has-tooltip:focus-visible::after {
  opacity: 1;
}

/* If tooltip would overflow top, place it below */
@supports (top: max(0px)) {
  .has-tooltip::after {
    top: auto;
    bottom: calc(100% + 6px);
  }

  .has-tooltip:hover::after {
    bottom: auto;
    top: calc(100% + 6px);
  }
}

/* ---------------------------------------------------------
   Definition Lists
   --------------------------------------------------------- */

dl {
  margin: 0;
}

dt {
  margin-top: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

dt:first-of-type {
  margin-top: 0;
}

dd {
  margin: 0.25rem 0 0.75rem 0;
  padding-left: 1rem;

  color: var(--color-text-secondary);
}

dt::before {
  content: "•";
  margin-right: 0.5rem;
  color: var(--color-text-muted);
}

dl.compact dt {
  margin-top: 0.75rem;
}

dl.compact dd {
  margin-bottom: 0.5rem;
}

/* ---------------------------------------------------------
   Header Logo (system = light)
   --------------------------------------------------------- */

.app-logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.app-logo img {
  height: 28px;
  width: auto;
}

/* SYSTEM DEFAULT (no data-theme) */
.logo-light {
  display: block;
}

.logo-dark {
  display: none;
}

/* EXPLICIT LIGHT */
:root[data-theme="light"] .logo-light {
  display: block;
}

:root[data-theme="light"] .logo-dark {
  display: none;
}

/* EXPLICIT DARK */
:root[data-theme="dark"] .logo-light {
  display: none;
}

:root[data-theme="dark"] .logo-dark {
  display: block;
}
