/* ============================================================
   BUILDYBOT — BASE APPLICATION STYLES
   Uses CSS variables from themes.css and layouts.css
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
  min-height: 100vh;
  margin: 0;
}

a { color: var(--primary); transition: color var(--transition-speed) ease; }
a:hover { color: var(--primary-hover); }

/* --- Cards --- */
.card {
  background-color: var(--surface);
  border: var(--card-border-w) var(--border-style) var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease, background-color var(--transition-speed) ease;
  overflow: hidden;
}
.card:hover {
  box-shadow: var(--shadow-lg);
}
.card .card-body { padding: 1.25rem; }
.card .card-title { color: var(--text); font-weight: 600; }
.card .card-text { color: var(--text-muted); }
.card .card-header {
  background-color: var(--surface-alt);
  border-bottom: 1px solid var(--border-color);
  color: var(--text);
}

/* --- Buttons --- */
.btn {
  border-radius: var(--radius-sm);
  border-width: var(--btn-border-w);
  border-style: var(--border-style);
  transition: all var(--transition-speed) ease;
  font-weight: 500;
  padding: 0.5rem 1.25rem;
}
.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}
.btn-secondary {
  background-color: var(--secondary);
  border-color: var(--secondary);
  color: var(--text);
}
.btn-secondary:hover {
  background-color: var(--secondary-hover);
  border-color: var(--secondary-hover);
}
.btn-outline-primary {
  background: transparent;
  border: var(--btn-border-w, 1px) solid var(--primary);
  color: var(--primary);
}
.btn-outline-primary:hover {
  background-color: var(--primary);
  color: #fff;
}
.btn-pill {
  border-radius: var(--radius-pill);
}

/* --- Forms --- */
.form-control {
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--input-radius);
  color: var(--text);
  transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
  padding: 0.6rem 1rem;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 0.2rem var(--input-focus-shadow);
  background-color: var(--input-bg);
  color: var(--text);
}
.form-label {
  color: var(--text);
  font-weight: 500;
  margin-bottom: 0.4rem;
}
.form-select {
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--input-radius);
  color: var(--text);
}
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 0.2rem var(--input-focus-shadow);
}
.form-text { color: var(--text-muted); }
.form-check-label { color: var(--text); }

/* --- Tables --- */
.table { color: var(--text); }
.table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.table td, .table th { border-color: var(--border-color); }

/* --- Alerts --- */
.alert { border-radius: var(--radius-sm); }

/* --- Badges --- */
.badge { border-radius: var(--radius-sm); }

/* --- Modal --- */
.modal-content {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.modal-header { border-bottom-color: var(--border-color); }
.modal-footer { border-top-color: var(--border-color); }

/* --- Footer --- */
.site-footer {
  background-color: var(--footer-bg);
  color: var(--footer-text);
  padding: 2rem 0;
  margin-top: auto;
  transition: background-color var(--transition-speed) ease;
}
.site-footer a { color: var(--footer-text); opacity: 0.8; text-decoration: none; }
.site-footer a:hover { opacity: 1; color: var(--footer-text); }

/* --- Interior Layout: full-width with left sidebar nav --- */
.interior-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.interior-sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border-color);
  transition: background-color var(--transition-speed) ease, border-color var(--transition-speed) ease;
}
.interior-sidebar-inner {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  text-align: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-nav-heading {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 1.25rem 0 0.4rem;
  padding-left: 0.5rem;
}
.sidebar-nav-heading:first-child { margin-top: 0.5rem; }

.sidebar-nav ul { margin-bottom: 0; }
.sidebar-nav-link {
  display: flex;
  align-items: center;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
  margin-bottom: 2px;
}
.sidebar-nav-link:hover {
  background: var(--bg-alt);
  color: var(--primary);
}
.sidebar-nav-link.active {
  background: var(--primary);
  color: #fff;
}
.sidebar-nav-link .badge { margin-left: auto; }

.sidebar-footer {
  padding-top: 0.5rem;
}

.interior-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.interior-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--surface);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.interior-content {
  flex: 1;
  padding: 1.5rem;
  background: var(--bg);
}

/* Mobile sidebar toggle button */
.sidebar-mobile-toggle {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border-color);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.sidebar-mobile-toggle i { font-size: 1.25rem; }

@media (max-width: 991.98px) {
  .interior-layout { flex-direction: column; }
  .sidebar-mobile-toggle { display: flex; }
  .interior-sidebar {
    width: 100%;
    min-width: 100%;
    border-right: none;
    display: none;
  }
  .interior-sidebar.sidebar-open {
    display: block;
    border-bottom: 1px solid var(--border-color);
  }
  .interior-sidebar-inner {
    position: static;
    height: auto;
    max-height: 60vh;
    padding: 1rem;
  }
}

/* --- Switcher Panel --- */
.switcher-panel {
  position: fixed;
  top: 0;
  right: -340px;
  width: 340px;
  height: 100vh;
  background: var(--surface);
  border-left: 2px solid var(--border-color);
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
  z-index: 9999;
  overflow-y: auto;
  transition: right 0.3s ease;
  padding: 1.5rem;
}
.switcher-panel.open { right: 0; }
.switcher-panel h6 {
  color: var(--text);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  margin: 1.25rem 0 0.6rem;
  font-weight: 700;
}
.switcher-panel h6:first-of-type { margin-top: 0; }

.switcher-toggle {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 10000;
  background: var(--primary);
  color: #fff;
  border: none;
  width: 36px;
  height: 80px;
  border-radius: 8px 0 0 8px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: -2px 0 8px rgba(0,0,0,0.15);
  transition: background-color var(--transition-speed) ease;
}
.switcher-toggle:hover { background: var(--primary-hover); }

.swatch-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.15s ease;
  position: relative;
}
.swatch-btn:hover { transform: scale(1.15); }
.swatch-btn.active {
  border-color: var(--text);
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.layout-btn {
  display: inline-block;
  padding: 0.3rem 0.6rem;
  font-size: 0.72rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.layout-btn:hover { background: var(--primary); color: #fff; }
.layout-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* --- Section Headings --- */
.section-heading {
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border-color);
}

/* --- Login Page --- */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 2rem;
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: var(--card-border-w) var(--border-style) var(--border-color);
  overflow: hidden;
  max-width: 500px;
  width: 100%;
}

/* --- Auth Layout (centered card for login/register) --- */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 2rem;
}

/* --- Utility --- */
.bg-surface { background-color: var(--surface) !important; }
.bg-surface-alt { background-color: var(--surface-alt) !important; }
.text-primary-custom { color: var(--primary) !important; }
.text-muted-custom { color: var(--text-muted) !important; }
.border-custom { border-color: var(--border-color) !important; }

/* --- Breadcrumbs --- */
.breadcrumb-item + .breadcrumb-item::before { color: var(--text-muted); }
.breadcrumb-item a { color: var(--primary); }
.breadcrumb-item.active { color: var(--text-muted); }

/* --- Compatibility: Nifty layout classes used in existing pages --- */
.content__boxed { max-width: 100%; }
.content__wrap { padding: 0; }
.content__header { margin-bottom: 1rem; }
.content__header .page-title { color: var(--text); font-weight: 700; }
.content__header .lead { color: var(--text-muted); }

/* --- Subnav styling --- */
.subnav-list .list-group-item {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--border-color);
}
.subnav-list .list-group-item.active {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}
.subnav-list .list-group-item.active:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
}
.subnav-list .list-group-item:not(.active):hover {
  background-color: var(--bg-alt);
}

/* --- Heading color fixes on colored backgrounds --- */
.bg-primary h1, .bg-primary h2, .bg-primary h3,
.bg-primary h4, .bg-primary h5, .bg-primary h6,
.bg-secondary h1, .bg-secondary h2, .bg-secondary h3,
.bg-secondary h4, .bg-secondary h5, .bg-secondary h6,
.bg-success h1, .bg-success h2, .bg-success h3,
.bg-success h4, .bg-success h5, .bg-success h6,
.bg-danger h1, .bg-danger h2, .bg-danger h3,
.bg-danger h4, .bg-danger h5, .bg-danger h6,
.bg-warning h1, .bg-warning h2, .bg-warning h3,
.bg-warning h4, .bg-warning h5, .bg-warning h6,
.bg-info h1, .bg-info h2, .bg-info h3,
.bg-info h4, .bg-info h5, .bg-info h6,
.bg-dark h1, .bg-dark h2, .bg-dark h3,
.bg-dark h4, .bg-dark h5, .bg-dark h6 {
  color: inherit;
}

/* --- Text colors that respect theme --- */
.text-muted { color: var(--text-muted) !important; }
.text-body-secondary { color: var(--text-muted) !important; }
h1, h2, h3, h4, h5, h6 { color: var(--text); }
p { color: var(--text); }
.list-group-item { color: var(--text); }

/* --- Toast container --- */
#toastContainer {
  z-index: 99999 !important;
}

/* --- Scroll to top --- */
.scroll-to-top {
  position: fixed;
  bottom: 2rem;
  right: 4rem;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: var(--shadow-sm);
  z-index: 9998;
  transition: opacity 0.3s ease;
}
.scroll-to-top.visible { display: flex; }
.scroll-to-top:hover { background: var(--primary-hover); }

/* --- DataTables theme integration --- */
.dataTables_wrapper .dataTables_filter input {
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--input-radius);
  color: var(--text);
  padding: 0.4rem 0.75rem;
}
.dataTables_wrapper .dataTables_filter input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 0.2rem var(--input-focus-shadow);
  outline: none;
}
.dataTables_wrapper .dataTables_info { color: var(--text-muted); }
.dataTables_wrapper .dataTables_paginate .paginate_button {
  color: var(--text) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: var(--primary) !important;
}
