@import url('../../assets/css/app-mobile.css');

:root {
  --primary: #2563eb;
  --secondary: #1e293b;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --mobile-topbar-h: 52px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: var(--secondary);
  color: #fff;
  padding: 1.5rem 1rem;
  flex-shrink: 0;
}
.sidebar h1 { font-size: 1.1rem; margin: 0 0 1.5rem; }
.sidebar nav a {
  display: block;
  color: #cbd5e1;
  padding: .6rem .75rem;
  border-radius: 8px;
  margin-bottom: .25rem;
}
.sidebar nav a:hover, .sidebar nav a.active {
  background: rgba(255,255,255,.1);
  color: #fff;
  text-decoration: none;
}
.demo-merchant-switch {
  margin: 1rem 0;
  padding: .75rem;
  background: rgba(255,255,255,.06);
  border-radius: 10px;
}
.demo-merchant-switch label {
  display: block;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #94a3b8;
  margin-bottom: .35rem;
}
.demo-merchant-select {
  width: 100%;
  padding: .5rem .6rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.2);
  background: #1e293b;
  color: #fff;
  font-size: .85rem;
}
.main { flex: 1; padding: 1.5rem; max-width: 1100px; }
.main h2 { margin-top: 0; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
.page-header h2 { margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.btn {
  display: inline-block;
  padding: .6rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}
.btn:hover { filter: brightness(1.05); }
.btn-secondary { background: #64748b; }
.btn-danger { background: var(--danger); }
.btn-sm { padding: .35rem .65rem; font-size: .85rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .9rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem; border-bottom: 1px solid var(--border); }
th { font-size: .8rem; text-transform: uppercase; color: var(--muted); }

.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-confirmed { background: #dbeafe; color: #1d4ed8; }
.badge-completed { background: #dcfce7; color: #15803d; }
.badge-cancelled { background: #fee2e2; color: #b91c1c; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card { width: 100%; max-width: 400px; }

.hidden { display: none !important; }
.customer-fields-readonly input {
  background: #f8fafc;
  color: #334155;
  cursor: default;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .5rem;
}
.cal-day {
  min-height: 100px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem;
  background: #fff;
  font-size: .8rem;
}
.cal-day .date { font-weight: 700; margin-bottom: .35rem; }
.cal-event {
  background: var(--primary);
  color: #fff;
  padding: .2rem .35rem;
  border-radius: 4px;
  margin-bottom: .2rem;
  font-size: .7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.cal-event:hover {
  filter: brightness(1.08);
}
.cal-day-expanded {
  min-height: auto;
}
.booking-row-clickable {
  cursor: pointer;
}
.booking-row-clickable:hover {
  background: #f8fafc;
}

/* Admin sidebar footer (also in nav.css for login page) */
.sidebar-footer {
  margin-top: 1.5rem;
  padding-top: .75rem;
  border-top: 1px solid rgba(255,255,255,.12);
}
.sidebar-footer a {
  display: block;
  color: #94a3b8;
  padding: .45rem .75rem;
  border-radius: 8px;
  font-size: .88rem;
  text-decoration: none;
}
.sidebar-footer a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-footer a.logout-link { color: #fca5a5; margin-top: .25rem; }

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

  /* Off-canvas sidebar drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 88vw);
    z-index: 60;
    padding: 1rem .75rem;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: none;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.45);
    z-index: 55;
  }
  body.sidebar-open .sidebar-backdrop { display: block; }
  body.sidebar-open { overflow: hidden; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    position: sticky;
    top: 0;
    z-index: 45;
    min-height: var(--mobile-topbar-h);
    padding: .5rem .75rem;
    margin: -1rem -1rem 1rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    flex-shrink: 0;
    color: var(--text);
  }
  .mobile-topbar-title {
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main {
    padding: 1rem;
    max-width: none;
    width: 100%;
  }
  .main > h2 { font-size: 1.25rem; }

  .form-row { grid-template-columns: 1fr; }
  .calendar-grid:not(.calendar-grid-month) { grid-template-columns: 1fr; }
  .calendar-grid-month .cal-day-month { min-height: 4.25rem; padding: .25rem; font-size: .65rem; }
  .calendar-grid-month .cal-event { font-size: .58rem; padding: .1rem .2rem; }
  .calendar-weekdays { font-size: .65rem; }

  .widget-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
  }
  .metric-card { padding: .85rem; }
  .metric-card .metric-value { font-size: 1.35rem; }

  .card { padding: 1rem; }

  /* Page headers with side actions */
  .page-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: .75rem !important;
  }
  .page-header .btn { width: 100%; text-align: center; }

  .btn:not(.btn-sm) {
    min-height: 44px;
    padding: .65rem 1rem;
  }

  .drawer {
    width: 100%;
    max-width: 100%;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  .login-page .card.login-card { margin-top: 5rem !important; }
}

@media (min-width: 769px) {
  .mobile-topbar,
  .sidebar-backdrop { display: none !important; }
}

@media (max-width: 400px) {
  .widget-grid { grid-template-columns: 1fr; }
}

/* ===========================================================================
   CRM / dashboard additions (additive; reused across desktop + mobile web)
   =========================================================================== */

/* Metric cards auto-fit and stack cleanly on small screens. */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.metric-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
a.metric-card.metric-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
a.metric-card.metric-card-link:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), var(--shadow);
}
a.metric-card.metric-card-link:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.metric-card .metric-label {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  margin: 0 0 .35rem;
}
.metric-card .metric-value { font-size: 1.6rem; font-weight: 700; margin: 0; }
.metric-card.alert-metric .metric-value { color: var(--danger); }
.metric-card.good-metric .metric-value { color: var(--success); }

/* Two-column panel layout that collapses to one column on mobile. */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 900px) {
  .panel-grid { grid-template-columns: 1fr; }
}

/* Activity feed. */
.feed-item {
  display: flex;
  gap: .6rem;
  padding: .6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.feed-item:last-child { border-bottom: none; }
.feed-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary); margin-top: .35rem; flex-shrink: 0;
}
.feed-dot.payment { background: var(--success); }
.feed-dot.failed { background: var(--danger); }
.feed-dot.cancelled { background: #f59e0b; }
.feed-time { color: var(--muted); font-size: .78rem; }

/* Tiny inline sparkline-ish bar chart for the revenue trend. */
.trend-bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.trend-bar { flex: 1; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.trend-bar:hover { opacity: 1; }

/* Simple right-side detail drawer for customer 360 view. */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: none; z-index: 50;
}
.drawer-overlay.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(520px, 100%);
  background: #fff; box-shadow: -4px 0 20px rgba(0,0,0,.15);
  padding: 1.25rem; overflow-y: auto; z-index: 51;
  transform: translateX(100%); transition: transform .2s ease;
}
.drawer.open { transform: translateX(0); }
.drawer .close-btn {
  float: right; background: none; border: none; font-size: 1.5rem;
  cursor: pointer; color: var(--muted); line-height: 1;
}
.tag-pill {
  display: inline-block; background: #eef2ff; color: #4338ca;
  padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; margin: 0 .25rem .25rem 0;
}
.stage-badge {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; text-transform: capitalize;
}
.stage-lead { background: #fef9c3; color: #854d0e; }
.stage-active { background: #dbeafe; color: #1d4ed8; }
.stage-repeat { background: #dcfce7; color: #15803d; }
.stage-inactive { background: #e2e8f0; color: #475569; }

.authnet-ref {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem;
  color: var(--primary);
  text-decoration: none;
  word-break: break-all;
}
.authnet-ref:hover { text-decoration: underline; }

.billing-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .75rem;
  margin-bottom: .5rem;
  background: #fff;
}
.billing-row-paid { border-left: 3px solid var(--success); }
.billing-row-open { border-left: 3px solid var(--primary); }
.billing-row.billing-paid { border-left: 3px solid var(--success); }
.billing-row.billing-open { border-left: 3px solid var(--primary); }
.billing-row-main { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.billing-row-actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .65rem; }
.billing-row a { color: inherit; text-decoration: none; }
.billing-row a:hover { text-decoration: underline; color: var(--primary); }
.billing-row .btn { text-decoration: none; }

.drawer-tabs {
  display: flex;
  gap: .35rem;
  margin: 1rem 0 .75rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.drawer-tab {
  flex-shrink: 0;
  padding: .45rem .85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  font-size: .85rem;
  cursor: pointer;
}
.drawer-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.drawer-panel.hidden { display: none !important; }

/* Compact data tables — fit in main panel without horizontal scroll */
.table-compact {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: .88rem;
}
.table-compact th,
.table-compact td {
  padding: .55rem .45rem;
  vertical-align: top;
  white-space: normal;
  word-break: break-word;
}
.table-compact thead th {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.table-compact tbody tr + tr td {
  border-top: 1px solid var(--border);
}
.table-compact .col-ref { width: 24%; }
.table-compact .col-customer { width: 16%; }
.table-compact .col-service { width: 22%; }
.table-compact .col-date { width: 11%; }
.table-compact .col-money { width: 12%; text-align: right; white-space: nowrap; }
.table-compact .col-status { width: 10%; }
.table-compact .col-when { width: 14%; }
.table-compact .cell-clip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  max-width: 100%;
}
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-top: .4rem;
}
.row-actions .btn-sm {
  padding: .22rem .45rem;
  font-size: .75rem;
  line-height: 1.2;
}
.slots-grid .book-slot-btn.selected,
.slots-grid .btn.selected {
  background: var(--primary, #2563eb);
  color: #fff;
  border-color: var(--primary, #2563eb);
}

.calendar-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}
.calendar-toolbar-group {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}
.view-toggle {
  display: inline-flex;
  gap: .25rem;
}
.view-toggle .btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.calendar-nav {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: wrap;
}
.cal-period-label {
  margin-left: .35rem;
  font-size: 1rem;
  min-width: 9rem;
}
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .5rem;
  margin-bottom: .35rem;
  font-size: .75rem;
  font-weight: 700;
  color: #64748b;
  text-align: center;
}
.calendar-weekdays.hidden { display: none; }
.cal-day.today {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}
.cal-day.other-month {
  background: #f8fafc;
  color: #94a3b8;
}
.cal-day.other-month .cal-event {
  opacity: .85;
}
.cal-day-month {
  min-height: 5.5rem;
}
.cal-more {
  font-size: .65rem;
  color: #64748b;
  margin-top: .15rem;
}

/* Legacy wrapper — only scroll on very narrow screens */
.table-scroll { overflow-x: visible; }
.table-scroll table { min-width: 0; width: 100%; }
@media (max-width: 520px) {
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .row-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .row-actions .btn-sm,
  .row-actions a.btn {
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }
}
