/* ============================================================
   Smart Home SaaS — Application Stylesheet
   Bootstrap 5.3 extended with custom brand system
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --brand-primary:     #6366f1;
  --brand-primary-dk:  #4f46e5;
  --brand-secondary:   #8b5cf6;
  --brand-accent:      #06b6d4;
  --brand-success:     #22c55e;
  --brand-warning:     #f59e0b;
  --brand-danger:      #ef4444;

  --sidebar-width:     260px;
  --topbar-height:     64px;

  --sidebar-bg:        #0f1117;
  --sidebar-text:      #94a3b8;
  --sidebar-active-bg: rgba(99,102,241,.15);
  --sidebar-active:    #6366f1;
  --sidebar-border:    rgba(255,255,255,.06);
  --sidebar-hover:     rgba(255,255,255,.05);

  --topbar-bg:         var(--bs-body-bg);
  --topbar-border:     var(--bs-border-color);

  --card-radius:       12px;
  --card-shadow:       0 2px 12px rgba(0,0,0,.06);
  --card-shadow-hover: 0 6px 20px rgba(0,0,0,.12);

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
}

body {
  display: flex;
  overflow-x: hidden;
  min-height: 100vh;
}

/* ── Layout Shell ──────────────────────────────────────────── */
.app-sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 1040;
  border-right: 1px solid var(--sidebar-border);
  transition: transform .25s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-content {
  flex: 1;
  padding: 1.5rem;
}

/* ── Sidebar Brand ─────────────────────────────────────────── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  min-height: var(--topbar-height);
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.brand-name {
  display: block;
  font-weight: 700;
  font-size: .95rem;
  color: #f1f5f9;
  letter-spacing: -.02em;
}

.brand-sub {
  display: block;
  font-size: .68rem;
  color: #64748b;
  margin-top: -1px;
}

/* ── Sidebar Navigation ────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: .75rem 0;
}

.sidebar-nav .nav {
  padding: 0 .75rem;
  gap: .15rem;
}

.nav-header {
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #475569;
  padding: 1rem .75rem .35rem;
  list-style: none;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem .75rem;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: .875rem;
  font-weight: 400;
  transition: background .15s ease, color .15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav .nav-link:hover:not(.disabled):not(.active) {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.sidebar-nav .nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
  font-weight: 500;
}

.sidebar-nav .nav-link.active .nav-icon {
  color: var(--sidebar-active);
}

.nav-icon {
  font-size: 1rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--sidebar-border);
}

.role-badge {
  font-size: .72rem;
  color: #64748b;
  display: flex;
  align-items: center;
}

/* ── Top Bar ───────────────────────────────────────────────── */
.app-topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--topbar-border);
  background: var(--topbar-bg);
  position: sticky;
  top: 0;
  z-index: 1030;
  gap: .75rem;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  color: #fff;
  font-weight: 700;
  font-size: .8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-menu-btn {
  color: inherit !important;
}

.user-name {
  font-weight: 500;
  font-size: .875rem;
}

/* ── Theme Toggle ──────────────────────────────────────────── */
.btn-theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bs-secondary-color);
  border: 1px solid var(--bs-border-color);
  background: transparent;
  transition: background .15s, color .15s;
  padding: 0;
}

.btn-theme-toggle:hover {
  background: var(--bs-secondary-bg);
  color: var(--bs-body-color);
}

/* ── Dashboard Cards ───────────────────────────────────────── */
.stat-card {
  border-radius: var(--card-radius);
  border: 1px solid var(--bs-border-color);
  padding: 1.25rem 1.5rem;
  background: var(--bs-body-bg);
  box-shadow: var(--card-shadow);
  transition: box-shadow .2s ease, transform .2s ease;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

.stat-card-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.stat-card-icon.primary   { background: rgba(99,102,241,.15);  color: #6366f1; }
.stat-card-icon.success   { background: rgba(34,197,94,.12);   color: #22c55e; }
.stat-card-icon.warning   { background: rgba(245,158,11,.12);  color: #f59e0b; }
.stat-card-icon.info      { background: rgba(6,182,212,.12);   color: #06b6d4; }
.stat-card-icon.danger    { background: rgba(239,68,68,.12);   color: #ef4444; }
.stat-card-icon.secondary { background: rgba(100,116,139,.12); color: #64748b; }

.stat-card-body {}
.stat-card-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.03em;
}
.stat-card-label {
  font-size: .78rem;
  color: var(--bs-secondary-color);
  font-weight: 500;
  margin-top: .15rem;
}

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0;
}

.page-subtitle {
  font-size: .82rem;
  color: var(--bs-secondary-color);
  margin-top: .2rem;
}

/* ── Section Cards ─────────────────────────────────────────── */
.section-card {
  border-radius: var(--card-radius);
  border: 1px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.section-card .section-card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--bs-border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: .9rem;
}

.section-card .section-card-body {
  padding: 1.25rem;
}

/* ── Tables ────────────────────────────────────────────────── */
.data-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

.data-table thead th {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--bs-secondary-color);
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--bs-border-color);
  background: var(--bs-secondary-bg);
  white-space: nowrap;
}

.data-table tbody tr {
  transition: background .1s ease;
}

.data-table tbody tr:hover {
  background: var(--bs-secondary-bg);
}

.data-table tbody td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--bs-border-color);
  vertical-align: middle;
  font-size: .875rem;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ── Status Badges ─────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .55rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-badge.active   { background: rgba(34,197,94,.12);  color: #16a34a; }
.status-badge.active::before { background: #22c55e; }
.status-badge.inactive { background: rgba(239,68,68,.1);   color: #dc2626; }
.status-badge.inactive::before { background: #ef4444; }
.status-badge.primary  { background: rgba(99,102,241,.12); color: #6366f1; }
.status-badge.primary::before { background: #6366f1; }
.status-badge.pending  { background: rgba(245,158,11,.12); color: #d97706; }
.status-badge.pending::before { background: #f59e0b; }

/* ── Role Badges ───────────────────────────────────────────── */
.role-pill {
  display: inline-flex;
  align-items: center;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.role-pill.super-admin    { background: rgba(99,102,241,.15); color: #6366f1; }
.role-pill.system-admin   { background: rgba(6,182,212,.12);  color: #0891b2; }
.role-pill.client         { background: rgba(34,197,94,.12);  color: #16a34a; }
.role-pill.client-assistant { background: rgba(245,158,11,.12); color: #d97706; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-control, .form-select {
  border-radius: 8px;
  font-size: .875rem;
}

.form-label {
  font-size: .82rem;
  font-weight: 500;
  margin-bottom: .35rem;
}

.form-text {
  font-size: .74rem;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  border-radius: 8px;
  font-weight: 500;
  font-size: .875rem;
}

.btn-primary {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
}

.btn-primary:hover {
  background: var(--brand-primary-dk);
  border-color: var(--brand-primary-dk);
}

.btn-icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 0;
  font-size: .85rem;
}

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
}

.empty-state-icon {
  font-size: 2.5rem;
  color: var(--bs-secondary-color);
  margin-bottom: 1rem;
  opacity: .5;
}

.empty-state-title {
  font-weight: 600;
  color: var(--bs-body-color);
  margin-bottom: .5rem;
}

.empty-state-text {
  font-size: .875rem;
  color: var(--bs-secondary-color);
}

/* ── Quick Action Buttons ──────────────────────────────────── */
.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 1rem;
  border-radius: 12px;
  border: 1.5px dashed var(--bs-border-color);
  text-decoration: none;
  color: var(--bs-body-color);
  font-size: .8rem;
  font-weight: 500;
  transition: border-color .2s, background .2s, transform .2s;
  min-height: 90px;
  text-align: center;
}

.quick-action:hover {
  border-color: var(--brand-primary);
  background: rgba(99,102,241,.06);
  color: var(--brand-primary);
  transform: translateY(-2px);
}

.quick-action i {
  font-size: 1.4rem;
}

/* ── Login Page ────────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 10px; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1199.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.show {
    transform: translateX(0);
    box-shadow: 0 0 0 1000px rgba(0,0,0,.45);
  }
  .app-main {
    margin-left: 0;
  }
  .sidebar-toggle {
    display: flex !important;
  }
}

/* ── Dark Mode Refinements ─────────────────────────────────── */
[data-bs-theme="dark"] {
  --topbar-bg: #0f172a;
  --topbar-border: rgba(255,255,255,.07);
}

[data-bs-theme="dark"] .section-card,
[data-bs-theme="dark"] .stat-card {
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
}

[data-bs-theme="dark"] .data-table thead th {
  background: rgba(255,255,255,.04);
}

[data-bs-theme="dark"] .status-badge.active {
  background: rgba(34,197,94,.18);
  color: #4ade80;
}

[data-bs-theme="dark"] .status-badge.inactive {
  background: rgba(239,68,68,.18);
  color: #f87171;
}
