@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box
}

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #121212;
  --bg-card: #181818;
  --bg-card-hover: #202020;
  --bg-input: #141414;
  --border: #2a2a2a;
  --border-focus: #d4af37;
  --text-primary: #f8f8f8;
  --text-secondary: #a0a0a0;
  --text-muted: #707070;
  --accent: #d4af37;
  --accent-hover: #f3c623;
  --accent-glow: rgba(212, 175, 55, 0.25);
  --success: #00d68f;
  --warning: #ffaa00;
  --danger: #ff4757;
  --info: #00b4d8;
  --gradient-1: linear-gradient(135deg, #d4af37, #aa8222);
  /* Gold to Bronze */
  --gradient-2: linear-gradient(135deg, #f3c623, #d4af37);
  /* Light Gold to Gold */
  --gradient-3: linear-gradient(135deg, #2a2a2a, #121212);
  /* Metallic Dark */
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px var(--accent-glow);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 50px;
  --sidebar-width: 260px;
  --topbar-height: 64px;
}

html,
body {
  height: 100%;
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  overflow-x: hidden;
  max-width: 100vw
}

a {
  color: var(--accent);
  text-decoration: none
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  outline: none
}

input,
select,
textarea {
  font-family: inherit;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  transition: .2s
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow)
}

::placeholder {
  color: var(--text-muted)
}

::-webkit-scrollbar {
  width: 6px
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary)
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px
}

/* Layout */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  max-width: 100vw;
  width: 100%
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: .3s;
  z-index: 100;
  position: fixed;
  height: 100vh
}

.sidebar.collapsed {
  width: 70px
}

.sidebar-brand {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border)
}

.sidebar-brand h1 {
  font-size: 20px;
  font-weight: 800;
  background: var(--gradient-1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 1px
}

.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  background: var(--gradient-1);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  -webkit-text-fill-color: #000
}

.sidebar.collapsed .sidebar-brand h1 {
  display: none
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: .2s;
  margin-bottom: 2px;
  white-space: nowrap;
  letter-spacing: 0.5px
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary)
}

.nav-item.active {
  background: var(--accent);
  color: #121212;
  box-shadow: var(--shadow-glow)
}

.nav-item .icon {
  font-size: 18px;
  width: 22px;
  text-align: center;
  flex-shrink: 0
}

.sidebar.collapsed .nav-item span:not(.icon) {
  display: none
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 8px
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border)
}

/* Main */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: .3s;
  min-width: 0;
  overflow-x: hidden;
  max-width: 100%
}

.sidebar.collapsed~.main {
  margin-left: 70px
}

.topbar {
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px
}

.topbar-title {
  font-size: 18px;
  font-weight: 600
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px
}

.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  min-width: 0
}

/* Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: .3s
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow)
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px
}

.stat-card:nth-child(1)::before {
  background: var(--gradient-1)
}

.stat-card:nth-child(2)::before {
  background: var(--gradient-2)
}

.stat-card:nth-child(3)::before {
  background: var(--gradient-3)
}

.stat-card:nth-child(4)::before {
  background: linear-gradient(135deg, #ffaa00, #ff6348)
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  margin: 8px 0 4px
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary)
}

.stat-icon {
  font-size: 32px;
  position: absolute;
  right: 16px;
  top: 16px;
  opacity: .15
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  transition: .2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px
}

.btn-primary {
  background: var(--gradient-1);
  color: #121212;
  border: none
}

.btn-primary:hover {
  background: var(--gradient-2);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px)
}

.btn-success {
  background: var(--success);
  color: #121212
}

.btn-danger {
  background: var(--danger);
  color: #fff
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border)
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(212, 175, 55, 0.05)
}

.btn-sm {
  padding: 6px 12px;
  font-size: 11px
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary)
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent)
}

/* Tables */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden
}

table {
  width: 100%;
  border-collapse: collapse
}

th {
  background: var(--bg-secondary);
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: .5px
}

td {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 14px
}

tr:hover td {
  background: var(--bg-card-hover)
}

/* Badge */
.badge {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px
}

.badge-success {
  background: rgba(0, 214, 143, .15);
  color: var(--success)
}

.badge-warning {
  background: rgba(255, 170, 0, .15);
  color: var(--warning)
}

.badge-danger {
  background: rgba(255, 71, 87, .15);
  color: var(--danger)
}

.badge-info {
  background: rgba(0, 180, 216, .15);
  color: var(--info)
}

.badge-primary {
  background: rgba(108, 92, 231, .15);
  color: var(--accent)
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: .2s
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow)
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600
}

.modal-body {
  padding: 24px
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px
}

/* Form */
.form-group {
  margin-bottom: 16px
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px
}

/* QR Code */
.qr-container {
  text-align: center;
  padding: 40px
}

.qr-container img {
  max-width: 280px;
  border-radius: var(--radius);
  border: 2px solid var(--border)
}

.qr-status {
  margin-top: 16px;
  font-size: 14px
}

.qr-status .connected {
  color: var(--success)
}

.qr-status .disconnected {
  color: var(--danger)
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px
}

.page-header h2 {
  font-size: 24px;
  font-weight: 700
}

/* Toggle */
.toggle {
  position: relative;
  width: 48px;
  height: 26px;
  appearance: none;
  background: var(--border);
  border-radius: 13px;
  cursor: pointer;
  transition: .2s
}

.toggle:checked {
  background: var(--accent)
}

.toggle::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: .2s
}

.toggle:checked::before {
  transform: translateX(22px)
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary)
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: .3
}

.empty-state p {
  margin-bottom: 20px
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

.fade-in {
  animation: fadeIn .3s ease;
  max-width: 100%;
  overflow-x: hidden;
  min-width: 0;
  word-wrap: break-word
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: .5
  }
}

.pulse {
  animation: pulse 2s infinite
}

@keyframes slideIn {
  from {
    transform: translateX(-100%)
  }

  to {
    transform: translateX(0)
  }
}

/* Global overflow containment for inline-styled elements */
.content * {
  max-width: 100%;
}

.content img {
  max-width: 100%;
  height: auto
}

/* Mobile overlay (background dim when sidebar open) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}
.sidebar-overlay.active {
  display: block;
}

/* Mobile */
@media(max-width:768px) {
  .nav-item.desktop-only { display: none !important }
  .sidebar {
    transform: translateX(-100%);
    position: fixed;
    width: 260px
  }

  .sidebar.mobile-open {
    transform: translateX(0)
  }

  .main {
    margin-left: 0 !important
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr
  }

  .form-row {
    grid-template-columns: 1fr
  }

  .topbar {
    padding: 0 12px
  }

  .topbar-title {
    font-size: 15px;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis
  }

  .content {
    padding: 12px 8px
  }

  .page-header {
    flex-direction: column;
    gap: 10px;
    align-items: stretch
  }

  .page-header h2 {
    font-size: 20px
  }

  .page-header > div {
    display: flex;
    flex-wrap: wrap;
    gap: 6px
  }

  /* Tables: horizontal scroll on mobile */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch
  }

  .table-wrap table {
    min-width: 500px
  }

  th, td {
    padding: 10px 8px;
    font-size: 12px
  }

  /* Stat cards */
  .stat-card {
    padding: 14px
  }

  .stat-value {
    font-size: 22px
  }

  .stat-icon {
    font-size: 24px;
    right: 10px;
    top: 10px
  }

  /* Buttons */
  .btn {
    padding: 8px 14px;
    font-size: 12px
  }

  .btn-sm {
    padding: 5px 10px;
    font-size: 10px
  }

  /* Calendar */
  .appt-layout {
    grid-template-columns: 1fr
  }

  .calendar-card {
    position: static
  }

  .cal-day {
    font-size: 12px
  }

  /* Chat - mobile full screen mode */
  .chat-container {
    flex-direction: column;
    height: calc(100vh - 140px);
    position: relative;
    border-radius: 8px
  }

  .chat-sidebar {
    width: 100%;
    height: 100%;
    border-right: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    background: var(--bg-card)
  }

  .chat-sidebar.mobile-hidden {
    display: none
  }

  .chat-sidebar-header {
    padding: 12px;
    font-size: 15px
  }

  .chat-list {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden
  }

  .chat-item {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    min-width: 0
  }

  .chat-main {
    width: 100%;
    height: 100%;
    min-width: 0
  }

  .chat-main.mobile-hidden {
    display: none
  }

  .chat-header {
    padding: 10px 12px
  }

  .chat-messages {
    padding: 10px
  }

  .chat-footer {
    padding: 8px 10px
  }

  .chat-footer input {
    padding: 8px 12px;
    font-size: 14px
  }

  .message-bubble {
    max-width: 85%;
    font-size: 13px;
    padding: 8px 12px
  }

  .chat-back-btn {
    display: inline-flex !important
  }

  /* Modal */
  .modal {
    width: 95%;
    max-width: 100%;
    max-height: 90vh;
    margin: 8px
  }

  .modal-header {
    padding: 14px 16px
  }

  .modal-body {
    padding: 16px
  }

  .modal-footer {
    padding: 12px 16px;
    flex-wrap: wrap
  }

  /* Toast */
  .toast-container {
    right: 8px;
    left: 8px;
    top: 70px
  }

  .toast {
    min-width: auto;
    font-size: 13px;
    padding: 10px 14px
  }

  /* Login */
  .login-card {
    padding: 24px 20px
  }

  .login-card h2 {
    font-size: 22px
  }

  /* Settings admin commands grid */
  .admin-commands-card div[style*="grid-template-columns"] {
    grid-template-columns: 1fr 1fr !important
  }

  /* QR Code page */
  .qr-container {
    padding: 20px
  }

  .qr-container img {
    max-width: 220px
  }

  /* Appointment items */
  .appt-item {
    padding: 10px 12px;
    gap: 10px;
    flex-wrap: wrap
  }

  .appt-details .appt-meta {
    font-size: 11px
  }

  .appt-actions {
    width: 100%;
    justify-content: flex-end
  }

  /* Settings sections */
  .content > .fade-in > div[style*="padding:24px"] {
    padding: 16px !important
  }

  /* Gallery grid */
  #gallery-grid > div {
    width: 60px !important;
    height: 60px !important
  }

  /* Search inputs in headers */
  .page-header input[type="text"],
  .page-header input[type="search"],
  .page-header input[id*="search"] {
    min-width: 0 !important;
    width: 100%;
    flex: 1
  }

  /* Force all inline-styled containers to not overflow */
  .content div[style*="display:flex"],
  .content div[style*="display: flex"] {
    flex-wrap: wrap !important
  }

  .content div[style*="gap:20px"],
  .content div[style*="gap: 20px"],
  .content div[style*="gap:16px"],
  .content div[style*="gap: 16px"] {
    gap: 10px !important
  }

  /* Force inline padding to be smaller on mobile */
  .content > .fade-in > div[style*="padding:24px"],
  .content > .fade-in > div[style*="padding: 24px"],
  .content div[style*="padding:24px"],
  .content div[style*="padding: 24px"] {
    padding: 14px !important
  }

  .content div[style*="padding:40px"],
  .content div[style*="padding: 40px"] {
    padding: 16px !important
  }

  .content div[style*="padding:32px"],
  .content div[style*="padding: 32px"] {
    padding: 14px !important
  }

  /* Force inline grids to be responsive */
  .content div[style*="grid-template-columns: repeat(auto-fill"],
  .content div[style*="grid-template-columns:repeat(auto-fill"] {
    grid-template-columns: 1fr 1fr !important
  }

  /* Contain all images */
  .content img {
    max-width: 100% !important;
    height: auto !important
  }

  /* QR code smaller on mobile */
  .content img[style*="width:280px"],
  .content img[style*="width: 280px"] {
    width: 200px !important;
    height: 200px !important
  }

  /* Cover photo */
  #cover-preview {
    height: 100px !important
  }

  /* Logo smaller */
  #logo-preview {
    width: 70px !important;
    height: 70px !important
  }

  /* Settings profile layout */
  .content div[style*="display:flex;gap:20px"] {
    flex-direction: column !important
  }

  /* Force max width on all child containers */
  .content .fade-in > * {
    max-width: 100% !important;
    overflow-x: hidden
  }

  /* Topbar right section */
  .topbar-right {
    gap: 6px
  }

  /* Stat card grid containment */
  .stats-grid {
    width: 100%
  }

  /* All cards must respect mobile width */
  .stat-card, .table-wrap, .calendar-card, .appt-list-card, .chat-container {
    max-width: 100%;
    overflow-x: auto
  }
}

@media(max-width:480px) {
  .stats-grid {
    grid-template-columns: 1fr
  }

  .topbar-right .badge {
    display: none
  }

  .topbar-right span {
    font-size: 11px !important
  }

  /* Admin commands: single column on very small screens */
  .admin-commands-card div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important
  }

  .chat-item-name {
    font-size: 13px
  }

  .chat-item-last {
    font-size: 10px !important
  }
}

/* Login Page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 20px
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow)
}

.login-card h2 {
  font-size: 28px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 8px;
  background: var(--gradient-1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px
}

.login-card .form-group {
  margin-bottom: 20px
}

.login-card .btn-primary {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  justify-content: center
}

.login-card .switch-link {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-secondary)
}

.login-card .switch-link a {
  cursor: pointer;
  color: var(--accent)
}

/* Notification toast */
.toast-container {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: fadeIn .3s;
  min-width: 280px
}

.toast-success {
  background: var(--success);
  color: #fff
}

.toast-error {
  background: var(--danger);
  color: #fff
}

.toast-info {
  background: var(--info);
  color: #fff
}

/* Calendar */
.appt-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start
}

.calendar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: sticky;
  top: 0
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px
}

.calendar-header .cal-title {
  font-size: 16px;
  font-weight: 700;
  text-transform: capitalize
}

.calendar-header .cal-nav {
  display: flex;
  gap: 4px
}

.calendar-header .cal-nav button {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: .2s
}

.calendar-header .cal-nav button:hover {
  border-color: var(--accent);
  color: var(--accent)
}

.calendar-header .cal-today {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: .2s;
  text-transform: uppercase;
  letter-spacing: .5px
}

.calendar-header .cal-today:hover {
  border-color: var(--accent);
  color: var(--accent)
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 4px
}

.calendar-weekdays span {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 0;
  text-transform: uppercase;
  letter-spacing: .5px
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: .15s;
  position: relative;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  gap: 2px
}

.cal-day:hover {
  background: var(--bg-input)
}

.cal-day.other-month {
  color: var(--text-muted);
  opacity: .35
}

.cal-day.today {
  color: var(--accent);
  font-weight: 700
}

.cal-day.today::after {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  bottom: 4px
}

.cal-day.selected {
  background: var(--accent);
  color: #121212;
  font-weight: 700;
  box-shadow: 0 0 12px var(--accent-glow)
}

.cal-day.selected::after {
  background: #121212
}

.cal-day .cal-dots {
  display: flex;
  gap: 2px;
  position: absolute;
  bottom: 3px
}

.cal-day .cal-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--info)
}

.cal-day.selected .cal-dots span {
  background: #121212
}

/* Appointment list */
.appt-list-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 200px
}

.appt-list-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between
}

.appt-list-header h3 {
  font-size: 15px;
  font-weight: 600
}

.appt-item {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: .15s
}

.appt-item:last-child {
  border-bottom: none
}

.appt-item:hover {
  background: var(--bg-card-hover)
}

.appt-time {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  min-width: 50px;
  text-align: center
}

.appt-time small {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted)
}

.appt-details {
  flex: 1;
  min-width: 0
}

.appt-details .appt-client {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.appt-details .appt-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 10px;
  flex-wrap: wrap
}

.appt-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0
}

.source-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 600;
  letter-spacing: .3px
}

.source-badge.whatsapp {
  background: rgba(37, 211, 102, .15);
  color: #25d366
}

.source-badge.painel {
  background: rgba(0, 180, 216, .15);
  color: var(--info)
}

@media(max-width:900px) {
  .appt-layout {
    grid-template-columns: 1fr
  }

  .calendar-card {
    position: static
  }
}

/* ===== VIEW TOGGLE ===== */
.view-toggle {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px
}

.view-toggle button {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: .2s;
  text-transform: uppercase;
  letter-spacing: .5px
}

.view-toggle button.active {
  background: var(--accent);
  color: #121212
}

.view-toggle button:hover:not(.active) {
  color: var(--text-primary)
}

/* ===== MATRIX VIEW ===== */
.matrix-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch
}

.matrix-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border)
}

.matrix-header h3 {
  font-size: 15px;
  font-weight: 600
}

.matrix-grid {
  display: grid;
  min-width: 600px
}

.matrix-grid-header {
  display: contents
}

.matrix-col-header {
  padding: 12px 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 2
}

.matrix-col-header small {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px
}

.matrix-time-label {
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  border-right: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding-top: 2px;
  background: var(--bg-card)
}

.matrix-cell {
  position: relative;
  border-bottom: 1px solid rgba(42, 42, 42, .4);
  border-right: 1px solid rgba(42, 42, 42, .2);
  min-height: 40px;
  background: var(--bg-card)
}

.matrix-cell:hover {
  background: var(--bg-card-hover)
}

.matrix-cell.hour-mark {
  border-bottom: 1px solid var(--border)
}

.matrix-block {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  line-height: 1.3;
  overflow: hidden;
  cursor: pointer;
  z-index: 1;
  transition: .15s;
  border-left: 3px solid;
  background: var(--bg-secondary)
}

.matrix-block:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  z-index: 5
}

.matrix-block .mb-service {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.matrix-block .mb-client {
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.matrix-block .mb-time {
  font-size: 10px;
  color: var(--text-muted)
}

.matrix-block .mb-actions {
  display: none;
  position: absolute;
  top: 2px;
  right: 4px;
  gap: 2px
}

.matrix-block:hover .mb-actions {
  display: flex
}

.matrix-block .mb-actions button {
  width: 20px;
  height: 20px;
  font-size: 10px;
  border-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0
}

.matrix-block .mb-actions button:hover {
  border-color: var(--accent);
  color: var(--accent)
}

.matrix-now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--danger);
  z-index: 3;
  pointer-events: none
}

.matrix-now-line::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger)
}

@media(max-width:768px) {
  .matrix-grid {
    min-width: 500px
  }

  .matrix-block {
    font-size: 10px;
    padding: 3px 5px
  }

  .matrix-col-header {
    font-size: 11px;
    padding: 8px 4px
  }
}

/* ===== CHAT INTERFACE ===== */
.chat-container {
  display: flex;
  height: calc(100vh - 180px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 16px;
}

.chat-sidebar {
  width: 300px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-body);
}

.chat-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-item:hover {
  background: var(--bg-input);
}

.chat-item.active {
  background: var(--bg-input);
  border-left: 4px solid var(--accent);
}

.chat-item-info {
  flex: 1;
  min-width: 0;
}

.chat-item-name {
  font-weight: 600;
  font-size: 14px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-last {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
}

.chat-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-image: radial-gradient(var(--border) 1px, transparent 0);
  background-size: 20px 20px;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.user {
  justify-content: flex-start;
}

.message-row.bot,
.message-row.admin {
  justify-content: flex-end;
}

.message-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-row.user .message-bubble {
  background: var(--bg-input);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}

.message-row.bot .message-bubble {
  background: #25d36620;
  color: var(--text-primary);
  border: 1px solid #25d36640;
  border-bottom-right-radius: 2px;
}

.message-row.admin .message-bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 2px;
}

.message-time {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 4px;
  display: block;
  text-align: right;
}

.chat-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

.chat-footer input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-input);
  color: var(--text-primary);
}

.chat-back-btn {
  display: none;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm)
}

.chat-footer .btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

@media (max-width: 768px) {
  .chat-sidebar {
    display: none;
  }

  .chat-container {
    height: calc(100vh - 140px);
  }
}

/* ===== Matrix Calendar Overhaul ===== */
.matrix-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  margin-top: 15px;
}
.matrix-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}
.matrix-grid {
  display: grid;
  background: white;
  border-bottom: 1px solid var(--border);
}
.matrix-col-header {
  background: #f9fafb;
  padding: 12px;
  text-align: center;
  font-weight: 600;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  color: #1f2937;
}
.matrix-col-header small {
  display: block;
  font-weight: normal;
  color: var(--text-secondary);
  font-size: 11px;
}
.matrix-time-label {
  padding: 0 10px;
  text-align: right;
  font-size: 13px;
  color: #6b7280;
  border-right: 1px solid var(--border);
  background: #ffffff;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding-top: 8px;
}
.matrix-time-label.hour-mark {
  border-top: 1px solid var(--border);
}
.matrix-cell {
  position: relative;
  border-right: 1px solid var(--border);
  border-bottom: 1px dashed #e5e7eb;
  background: #ffffff;
}
.matrix-cell.hour-mark {
  border-top: 1px solid var(--border);
}

/* Appointment Blocks */
.matrix-block {
  position: absolute;
  left: 3px;
  right: 6px;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 13px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 5;
  border-left-width: 4px;
  border-left-style: solid;
}
.mb-client { font-weight: 700; color: #1f2937; margin-bottom: 2px; }
.mb-service { color: #4b5563; font-size: 12px; }
.mb-bottom { 
  margin-top: auto; 
  display: flex; 
  justify-content: flex-end; 
}
.mb-status-btn {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  color: #6b7280;
}
.mb-status-btn:hover { background: #f3f4f6; }

/* Status Colors based on User Mockup */
.status-pendente { border-left-color: #EAB308 !important; background-color: #fef9c3 !important; }
.status-confirmado { border-left-color: #22C55E !important; background-color: #dcfce7 !important; }
.status-in_progress { border-left-color: #3B82F6 !important; background-color: #dbeafe !important; }
.status-noshow { border-left-color: #EF4444 !important; background-color: #fee2e2 !important; }
.status-concluido { border-left-color: #94A3B8 !important; background-color: #f1f5f9 !important; }
.status-default { border-left-color: #94A3B8 !important; background-color: #f1f5f9 !important; }

/* Legend */
.matrix-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  font-size: 13px;
  color: #4b5563;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.bg-pendente { background-color: #EAB308; }
.bg-confirmado { background-color: #22C55E; }
.bg-in_progress { background-color: #3B82F6; }
.bg-noshow { background-color: #EF4444; }
.bg-concluido { background-color: #94A3B8; }

/* Blocked / Diagonal lines for empty hash cells */
.matrix-cell.blocked {
  background-image: repeating-linear-gradient(
    45deg,
    #f9fafb,
    #f9fafb 10px,
    #ffffff 10px,
    #ffffff 20px
  );
}

/* ===== Inventory & POS UI ===== */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  display: flex;
  flex-direction: column;
}
.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.stat-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--bg-card);
}
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table-wrap th {
  background: var(--bg-secondary);
  padding: 12px 15px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.table-wrap td {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.table-wrap tr:last-child td {
  border-bottom: none;
}