@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Inter:wght@300;400;500;600&display=swap');

/* ─── Reset ─────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Variables ─────────────────────────────────── */
:root {
  --black:        #0a0a0a;
  --white:        #ffffff;
  --cream:        #f8f4ef;
  --cream-dark:   #ede8e0;
  --gold:         #c9a84c;
  --gold-light:   #e8d5a3;
  --gold-dark:    #9a7a2e;
  --gray-100:     #f5f5f5;
  --gray-200:     #e8e8e8;
  --gray-400:     #a0a0a0;
  --gray-600:     #666666;
  --gray-800:     #333333;
  --success:      #2d6a4f;
  --danger:       #9b2226;
  --warning:      #ae6800;
  --font-serif:   'Playfair Display', Georgia, serif;
  --font-sans:    'Inter', system-ui, sans-serif;
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    16px;
  --radius-xl:    24px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.14);
  --transition:   all 0.2s ease;
  --sidebar-w:    240px;
  --topbar-h:     60px;
}

/* ─── Base ───────────────────────────────────────── */
html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--black);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 15px; }

p { line-height: 1.7; color: var(--gray-600); }

a { text-decoration: none; color: inherit; }

input, textarea, select, button {
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  border: none;
}

/* ─── Scrollbar ──────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--cream-dark);
  border-radius: 10px;
}

/* ─── App Layout ─────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Auth Pages ─────────────────────────────────── */
#auth-screen {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black);
  position: relative;
  overflow: hidden;
}

#auth-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(ellipse at 20% 50%, rgba(201,168,76,0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(201,168,76,0.05) 0%, transparent 50%);
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 {
  font-size: 32px;
  color: var(--black);
  letter-spacing: -0.5px;
}

.auth-logo h1 em {
  font-style: italic;
  color: var(--gold);
}

.auth-logo p {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gray-400);
  margin-top: 4px;
}

.auth-tabs {
  display: flex;
  background: var(--gray-100);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: 28px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  transition: var(--transition);
}

.auth-tab.active {
  background: var(--white);
  color: var(--black);
  box-shadow: var(--shadow-sm);
}

/* ─── Form Elements ──────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  background: var(--white);
  color: var(--black);
  font-size: 14px;
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.12);
}

.form-control::placeholder {
  color: var(--gray-400);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ─── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1.5px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--black);
  color: var(--white);
  border-color: var(--black);
}

.btn-primary:hover {
  background: var(--gray-800);
}

.btn-gold {
  background: var(--gold);
  color: var(--white);
  border-color: var(--gold);
}

.btn-gold:hover {
  background: var(--gold-dark);
  border-color: var(--gold-dark);
}

.btn-outline {
  background: transparent;
  color: var(--black);
  border-color: var(--gray-200);
}

.btn-outline:hover {
  background: var(--gray-100);
  border-color: var(--gray-400);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: var(--white);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
}

/* ─── Sidebar ────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--black);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition);
}

.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand h2 {
  font-size: 20px;
  color: var(--white);
  letter-spacing: -0.3px;
}

.sidebar-brand h2 em {
  font-style: italic;
  color: var(--gold);
}

.sidebar-brand p {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--gray-400);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  color: var(--gray-400);
  font-size: 13px;
  font-weight: 400;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--white);
}

.nav-item.active {
  background: rgba(201,168,76,0.12);
  color: var(--gold);
  border-color: rgba(201,168,76,0.2);
}

.nav-item .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 8px 0;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.shop-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.shop-info:hover {
  background: rgba(255,255,255,0.05);
}

.shop-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
  flex-shrink: 0;
}

.shop-details {
  flex: 1;
  overflow: hidden;
}

.shop-details .shop-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shop-details .shop-plan {
  font-size: 10px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ─── Main Content ───────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--cream);
}

/* ─── Topbar ─────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}

.topbar-title {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.topbar-title em {
  font-style: italic;
  color: var(--gold);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Page Content ───────────────────────────────── */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ─── Cards ──────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  overflow: hidden;
}

.card-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

/* ─── Stat Cards ─────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gold);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card .stat-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gray-400);
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  color: var(--black);
  line-height: 1;
}

.stat-card .stat-sub {
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 4px;
}

/* ─── Table ──────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gray-400);
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--gray-800);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: var(--transition);
  cursor: pointer;
}

tbody tr:hover {
  background: var(--cream);
}

/* ─── Badges ─────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.badge-gold {
  background: rgba(201,168,76,0.12);
  color: var(--gold-dark);
}

.badge-success {
  background: rgba(45,106,79,0.1);
  color: var(--success);
}

.badge-danger {
  background: rgba(155,34,38,0.1);
  color: var(--danger);
}

.badge-warning {
  background: rgba(174,104,0,0.1);
  color: var(--warning);
}

.badge-gray {
  background: var(--gray-100);
  color: var(--gray-600);
}

/* ─── Search Bar ─────────────────────────────────── */
.search-wrap {
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  background: var(--white);
  color: var(--black);
  font-size: 13px;
  transition: var(--transition);
}

.search-wrap input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.10);
}

.search-wrap::before {
  content: '⌕';
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: 16px;
  pointer-events: none;
}

/* ─── Canvas Area ────────────────────────────────── */
.canvas-container {
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--white);
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--cream);
  border-bottom: 1px solid var(--gray-200);
  flex-wrap: wrap;
}

.canvas-pages {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  background: var(--gray-100);
  border-bottom: 1px solid var(--gray-200);
  overflow-x: auto;
}

.page-tab {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  background: var(--white);
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
  transition: var(--transition);
  white-space: nowrap;
}

.page-tab.active {
  background: var(--black);
  color: var(--white);
  border-color: var(--black);
}

.page-tab-add {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  background: transparent;
  border: 1px dashed var(--gray-400);
  color: var(--gray-400);
  transition: var(--transition);
}

.page-tab-add:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.canvas-wrap {
  position: relative;
  background: var(--white);
  height: 420px;
}

canvas#drawCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* ─── Delivery Cards ─────────────────────────────── */
.delivery-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.delivery-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--white);
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  transition: var(--transition);
  cursor: pointer;
}

.delivery-item:hover {
  border-color: var(--gold-light);
  box-shadow: var(--shadow-sm);
}

.delivery-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--cream-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 600;
  color: var(--gold-dark);
  flex-shrink: 0;
}

.delivery-info {
  flex: 1;
  overflow: hidden;
}

.delivery-info .d-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--black);
}

.delivery-info .d-note {
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delivery-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ─── Customer List ──────────────────────────────── */
.customer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: var(--transition);
}

.customer-item:hover {
  background: var(--cream);
}

.customer-item:last-child {
  border-bottom: none;
}

.customer-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--cream-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 600;
  color: var(--gold-dark);
  flex-shrink: 0;
}

.customer-info {
  flex: 1;
  overflow: hidden;
}

.customer-info .c-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--black);
}

.customer-info .c-phone {
  font-size: 12px;
  color: var(--gray-400);
}

.customer-info .c-members {
  font-size: 11px;
  color: var(--gold-dark);
  margin-top: 2px;
}

/* ─── Payment Bill ───────────────────────────────── */
.bill-items {
  width: 100%;
  border-collapse: collapse;
}

.bill-items td {
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-100);
}

.bill-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--gray-200);
}

.bill-total-row.final {
  border-top: 2px solid var(--black);
  font-weight: 600;
  font-size: 16px;
}

/* ─── Modal ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--white);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 1;
}

.modal-header h3 {
  font-size: 18px;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--gray-100);
  color: var(--gray-600);
  font-size: 18px;
  transition: var(--transition);
  border: none;
}

.modal-close:hover {
  background: var(--gray-200);
}

/* ─── Toast ──────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--white);
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  max-width: 300px;
}

.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--black); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ─── Loading ────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.page-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--gray-400);
  font-size: 13px;
  gap: 10px;
}

/* ─── Empty State ────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state h4 {
  font-family: var(--font-serif);
  font-size: 18px;
  color: var(--gray-600);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
  margin-bottom: 20px;
}

/* ─── Tags ───────────────────────────────────────── */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--cream-dark);
  color: var(--gray-800);
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
}

.tag.selected {
  background: var(--black);
  color: var(--white);
}

.tag:hover:not(.selected) {
  border-color: var(--gold);
  color: var(--gold-dark);
}

/* ─── Phone Check ────────────────────────────────── */
.phone-check-result {
  background: var(--cream);
  border: 1px solid var(--cream-dark);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 8px;
  display: none;
}

.phone-check-result.visible {
  display: block;
}

/* ─── Stats Charts ───────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 260px;
  width: 100%;
}

/* ─── Mobile Responsive ──────────────────────────── */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 0px;
  }

  #sidebar {
    position: fixed;
    left: -240px;
    z-index: 100;
    transition: left 0.25s ease;
    width: 240px;
  }

  #sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }

  .sidebar-overlay.visible {
    display: block;
  }

  #content {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .modal {
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    position: fixed;
    bottom: 0;
    max-height: 85vh;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
}

/* ─── Utility ────────────────────────────────────── */
.hidden   { display: none !important; }
.flex     { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-8    { gap: 8px; }
.gap-12   { gap: 12px; }
.gap-16   { gap: 16px; }
.gap-24   { gap: 24px; }
.mt-8     { margin-top: 8px; }
.mt-16    { margin-top: 16px; }
.mt-24    { margin-top: 24px; }
.mb-8     { margin-bottom: 8px; }
.mb-16    { margin-bottom: 16px; }
.mb-24    { margin-bottom: 24px; }
.text-gold   { color: var(--gold); }
.text-muted  { color: var(--gray-400); }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.font-serif  { font-family: var(--font-serif); }
.italic      { font-style: italic; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.w-full      { width: 100%; }
.divider {
  height: 1px;
  background: var(--gray-200);
  margin: 16px 0;
}