/* ======================================================
   DESIGN REFRESH - SAFE GLOBAL OVERRIDES
   Applies after existing styles for consistent UI polish
====================================================== */

:root {
  --ui-surface-1: rgba(15, 23, 42, 0.72);
  --ui-surface-2: rgba(30, 41, 59, 0.7);
  --ui-ring: rgba(59, 130, 246, 0.32);
  --ui-radius-lg: 18px;
}

body {
  background:
    radial-gradient(1100px 480px at 115% -10%, rgba(59, 130, 246, 0.12), transparent 60%),
    radial-gradient(900px 420px at -20% 0%, rgba(139, 92, 246, 0.08), transparent 56%),
    var(--bg);
}

.app {
  isolation: isolate;
}

/* Sidebar position is set in base (fixed right desktop / off-canvas mobile) */
.sidebar {
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.menu {
  padding-left: 4px;
}

.menu a {
  min-height: 46px;
  border: 1px solid transparent;
}

.menu a:hover {
  border-color: var(--border-light);
}

.menu a.active {
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.35), 0 8px 20px -14px rgba(59, 130, 246, 0.7);
}

.content {
  background:
    linear-gradient(180deg, rgba(17, 24, 39, 0.3), rgba(17, 24, 39, 0) 35%),
    var(--bg);
}

.topbar {
  gap: 12px;
  padding-inline: clamp(16px, 2vw, 30px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.page-title {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-box {
  margin-inline-start: auto;
}

.user-info span {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-main {
  width: 100%;
  max-width: 1600px;
  margin-inline: auto;
  padding: clamp(16px, 2vw, 30px);
}

.page-main > * {
  width: 100%;
}

.page-main .grid {
  gap: clamp(12px, 1.8vw, 22px);
}

.section-title {
  margin: 0 0 16px;
  line-height: 1.4;
}

.card {
  border-radius: var(--ui-radius-lg);
}

.card-header {
  gap: 14px;
  flex-wrap: wrap;
}

.menu-badge {
  display: none;
  margin-right: 8px;
  background: var(--danger);
  color: #fff;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  min-width: 20px;
  justify-content: center;
}

.table-container {
  border-radius: 14px;
  border-color: rgba(255, 255, 255, 0.12);
}

table th {
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
  backdrop-filter: blur(8px);
}

tbody tr:hover {
  transform: none;
}

.btn,
button,
.logout,
input,
select,
textarea {
  min-height: 44px;
}

input,
select,
textarea {
  background: rgba(2, 6, 23, 0.28);
}

input:focus,
select:focus,
textarea:focus {
  box-shadow: 0 0 0 3px var(--ui-ring);
}

.orders-card,
.report-card,
.chart-card,
.stat-card {
  border-radius: var(--ui-radius-lg);
}

.modal {
  backdrop-filter: blur(8px);
}

.modal .card {
  max-height: min(88vh, 920px);
  overflow-y: auto;
}

.footer {
  padding: 16px 22px;
}

@media (max-width: 900px) {
  .sidebar {
    height: 100dvh;
  }

  .topbar-left {
    flex: 1 1 100%;
  }

  .page-title {
    white-space: normal;
  }

  .user-box {
    margin-inline-start: 0;
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 640px) {
  .page-main {
    padding: 14px;
  }
}

/* ======================================================
   DASHBOARD POLISH (`index.html`)
====================================================== */

.dashboard-welcome {
  min-height: 60vh;
  padding: 60px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.dashboard-welcome-title {
  margin: 0 0 20px;
  font-size: clamp(26px, 4vw, 34px);
  font-weight: 700;
  color: #e2e8f0;
}

.dashboard-welcome-subtitle {
  margin: 0 0 34px;
  font-size: clamp(16px, 2.4vw, 19px);
  color: #94a3b8;
}

.dashboard-welcome-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  max-width: 680px;
}

.dashboard-welcome-pos-btn {
  padding: 16px 32px;
  border-radius: 12px;
  text-decoration: none;
  color: #fff;
  font-weight: 600;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.dashboard-welcome-pos-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(59, 130, 246, 0.35);
}

.dashboard-topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.dashboard-add-expense-btn {
  padding: 8px 16px;
  font-size: 13px;
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.dashboard-period-btn {
  position: relative;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(124, 58, 237, 0.15));
  color: #8b5cf6;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.dashboard-period-caret {
  margin-right: 4px;
  font-size: 12px;
}

.dashboard-grid-single {
  grid-template-columns: 1fr;
  margin-bottom: 24px;
}

.dashboard-grid-metrics {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin-bottom: 24px;
}

.metric-title {
  font-weight: 600;
  color: #94a3b8;
}

.metric-note {
  color: #64748b;
}

.metric-count {
  letter-spacing: 0.2px;
}

.dashboard-card-highlight {
  text-align: center;
  padding: 32px;
  border: 2px solid transparent;
}

.dashboard-card-highlight .metric-title {
  margin-bottom: 12px;
  font-size: 18px;
}

.dashboard-card-highlight .metric-note {
  margin-top: 8px;
  font-size: 13px;
}

.dashboard-card-highlight .count.metric-count {
  font-size: 48px;
  font-weight: 700;
}

.metric-card {
  border: 2px solid transparent;
}

.metric-card .metric-title {
  margin-bottom: 8px;
  font-size: 16px;
}

.metric-card .metric-note {
  margin-top: 8px;
  font-size: 12px;
}

.metric-card .count.metric-count {
  font-size: 36px;
}

.dashboard-card-highlight.is-cash {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(5, 150, 105, 0.2));
  border-color: rgba(16, 185, 129, 0.4);
}

.dashboard-card-highlight.is-cash .count.metric-count {
  color: #10b981;
}

.dashboard-card-highlight.is-profit {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(124, 58, 237, 0.2));
  border-color: rgba(139, 92, 246, 0.4);
}

.dashboard-card-highlight.is-profit .count.metric-count {
  color: #8b5cf6;
}

.metric-card.is-sales {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(37, 99, 235, 0.15));
  border-color: rgba(59, 130, 246, 0.4);
}

.metric-card.is-sales .count.metric-count {
  color: #3b82f6;
}

.metric-card.is-cash-sales {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(5, 150, 105, 0.15));
  border-color: rgba(16, 185, 129, 0.4);
}

.metric-card.is-cash-sales .count.metric-count {
  color: #10b981;
}

.metric-card.is-credit-sales {
  background: linear-gradient(135deg, rgba(251, 146, 60, 0.2), rgba(249, 115, 22, 0.15));
  border-color: rgba(251, 146, 60, 0.4);
}

.metric-card.is-credit-sales .count.metric-count {
  color: #fb923c;
}

.metric-card.is-inventory {
  background: linear-gradient(135deg, rgba(251, 146, 60, 0.2), rgba(249, 115, 22, 0.15));
  border-color: rgba(251, 146, 60, 0.4);
}

.metric-card.is-inventory .count.metric-count {
  color: #fb923c;
}

.metric-card.is-liabilities {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(220, 38, 38, 0.15));
  border-color: rgba(239, 68, 68, 0.4);
}

.metric-card.is-liabilities .count.metric-count {
  color: #ef4444;
}

.metric-card.is-agent-dues {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(124, 58, 237, 0.15));
  border-color: rgba(139, 92, 246, 0.4);
  cursor: pointer;
}

.metric-card.is-agent-dues .count.metric-count {
  color: #8b5cf6;
}

.metric-card-icon-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.metric-card-icon-title .emoji {
  font-size: 20px;
}

.search-actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}

.search-action-btn {
  flex: 1;
  min-width: 100px;
}

.search-action-btn.is-primary {
  min-width: 120px;
}

.search-action-btn.is-danger {
  background: #ef4444;
}

.search-results-wrap {
  max-height: 400px;
  overflow-y: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.modal-close-btn-soft {
  width: 100%;
  margin-top: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
}

.expense-form-actions {
  display: flex;
  gap: 12px;
}

.expense-form-actions .btn {
  flex: 1;
}

.period-modal-card {
  max-width: 500px;
  width: 95%;
}

.period-modal-title {
  margin: 0 0 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #f1f5f9;
  font-size: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.period-options-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 24px;
}

.period-custom-range {
  margin-bottom: 20px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.period-custom-range-title {
  margin: 0 0 12px;
  color: #f1f5f9;
  font-size: 16px;
}

.period-custom-range-fields {
  display: grid;
  gap: 12px;
}

.period-apply-btn {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}

/* ======================================================
   ORDERS PAGE POLISH (`orders.html`)
====================================================== */

.u-mb-20 {
  margin-bottom: 20px;
}

.orders-stat-icon-primary {
  background: rgba(59, 130, 246, 0.2);
  color: var(--orders-primary);
}

.orders-stat-icon-success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--orders-success);
}

.orders-stat-icon-warning {
  background: rgba(245, 158, 11, 0.2);
  color: var(--orders-warning);
}

.orders-stat-icon-danger {
  background: rgba(239, 68, 68, 0.2);
  color: var(--orders-danger);
}

.orders-actions-title {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
  color: var(--orders-text);
}

.orders-section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.orders-section-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.orders-toggle-btn {
  padding: 8px 16px;
  font-size: 14px;
  white-space: nowrap;
  border: none;
  cursor: pointer;
  border-radius: 12px;
  font-weight: 600;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.orders-selected-count {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--orders-primary);
  background: rgba(59, 130, 246, 0.1);
}

@media (max-width: 768px) {
  .dashboard-welcome {
    min-height: 52vh;
    padding: 34px 18px;
  }

  .dashboard-topbar-actions {
    width: 100%;
  }

  .dashboard-topbar-actions > .btn {
    flex: 1 1 140px;
    justify-content: center;
  }

  .dashboard-card-highlight .count.metric-count {
    font-size: 38px;
  }

  .metric-card .count.metric-count {
    font-size: 30px;
  }
}

/* ======================================================
   DESKTOP SAFETY OVERRIDES
   Prevent phone layout on desktop browsers
====================================================== */

/* Narrow viewport with pointer: keep desktop layout (sidebar fixed right, no drawer) */
@media (max-width: 900px) and (hover: hover) and (pointer: fine) {
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    transform: none !important;
    width: 280px !important;
    height: 100vh !important;
    box-shadow: var(--shadow-sm) !important;
    pointer-events: auto !important;
    will-change: auto !important;
  }

  .sidebar ~ .content {
    margin-right: 280px !important;
    width: auto !important;
  }

  .toggle {
    display: none !important;
  }

  .sidebar-close-btn {
    display: none !important;
  }

  .app.sidebar-open::before {
    content: none !important;
    display: none !important;
  }
}

@media (max-width: 767px) and (hover: hover) and (pointer: fine) {
  .mobile-bottom-nav {
    display: none !important;
  }

  .content {
    padding-bottom: 0 !important;
  }

  main,
  .page-main {
    padding-bottom: 16px !important;
  }
}
