/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--surface-0);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { min-height: 100dvh; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* Typography */
.page-title {
  font-family: var(--font-voice);
  font-size: 22px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--text-primary);
}

.section-heading {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-primary);
}

.text-body { font-size: 14px; font-weight: 400; line-height: 1.5; }
.text-compact { font-size: 13px; font-weight: 400; line-height: 1.4; }
.text-small { font-size: 12px; font-weight: 400; line-height: 1.4; }
.text-caption { font-size: 11px; font-weight: 500; line-height: 1.3; color: var(--text-muted); }
.text-micro { font-size: 10px; font-weight: 500; line-height: 1.2; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.mono { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

/* Wordmark */
.wordmark { font-family: var(--font-voice); font-size: 18px; letter-spacing: -0.01em; color: var(--text-primary); }
.wordmark-italic { font-style: italic; font-weight: 400; }
.wordmark-bold { font-weight: 500; }

/* Layout */
.app-shell { display: flex; flex-direction: column; min-height: 100dvh; }

.page-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-5);
  width: 100%;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  border: 0.5px solid var(--border-strong);
  background: transparent;
  color: var(--text-primary);
  transition: background 120ms ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-1); }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--fill-primary);
  color: var(--on-primary);
  border: none;
  padding: 7px 14px;
}
.btn-primary:hover { opacity: 0.9; background: var(--fill-primary); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 6px 10px;
}
.btn-ghost:hover { color: var(--text-primary); }

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 6px 12px;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.btn-outline:hover:not(:disabled) { border-color: var(--text-secondary); color: var(--text-primary); }
.btn-outline:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-outline.text-danger { color: #e57373; border-color: #e57373; }
.btn-outline.text-danger:hover:not(:disabled) { background: rgba(229,115,115,0.08); }

/* Form controls */
.input {
  height: 36px;
  padding: 0 12px;
  font-size: 13px;
  background: var(--surface-2);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-primary);
  width: 100%;
  outline: none;
  transition: outline 120ms;
}
.input:focus { outline: 2px solid var(--border-accent); outline-offset: 0; }
.input::placeholder { color: var(--text-muted); }

.input-with-icon {
  position: relative;
}
.input-with-icon .input { padding-left: 34px; }
.input-with-icon .input-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
  pointer-events: none;
}

/* Cards */
.card {
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
}

.card-metric {
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-card);
  padding: 12px 14px;
}
.metric-label { font-size: 11px; font-weight: 500; color: var(--text-secondary); margin: 0 0 4px; }
.metric-value { font-size: 22px; font-weight: 500; color: var(--text-primary); margin: 0; }
.metric-delta { font-size: 11px; margin: 3px 0 0; }
.metric-delta-up { color: var(--text-success); }
.metric-delta-down { color: var(--text-danger); }
.metric-delta-flat { color: var(--text-muted); }

/* Status pills */
.pill {
  font-size: 11px;
  font-weight: 400;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  display: inline-block;
  line-height: 1.4;
}
.pill-success { background: var(--bg-success); color: var(--text-success); }
.pill-warning { background: var(--bg-warning); color: var(--text-warning); }
.pill-danger { background: var(--bg-danger); color: var(--text-danger); }
.pill-neutral { background: var(--surface-1); color: var(--text-secondary); border: 0.5px solid var(--border); }
.pill-pro { background: var(--bg-pro); color: var(--text-pro); }
.pill-accent { background: var(--bg-accent); color: var(--text-accent); }

/* Tables (CSS grid) */
.table {
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
}
.table-head, .table-row {
  display: grid;
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--border);
  align-items: center;
}
.table-head { font-size: 11px; font-weight: 500; font-style: italic; color: var(--text-muted); padding: 9px 14px; }
.table-row { font-size: 13px; color: var(--text-primary); }
.table-row:last-child { border-bottom: 0; }
.table-row:hover { background: var(--surface-1); cursor: pointer; }

/* Tabs (underline) */
.tabs { display: flex; gap: 22px; border-bottom: 0.5px solid var(--border); }
.tab {
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  position: relative;
}
.tab-count { color: var(--text-muted); margin-left: 2px; }
.tab-active {
  color: var(--text-primary);
  font-weight: 500;
  border-bottom: 1.5px solid var(--text-primary);
  margin-bottom: -0.5px;
}
.tab-active .tab-count { font-weight: 400; }

/* Segment control (pill group) */
.seg {
  display: inline-flex;
  gap: 2px;
  background: var(--surface-2);
  padding: 3px;
  border-radius: var(--radius-pill);
  border: 0.5px solid var(--border);
}
.seg-item {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
}
.seg-item-active { background: var(--surface-1); color: var(--text-primary); font-weight: 500; }

/* Filter chips */
.chip {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
}
.chip-active {
  background: var(--surface-2);
  color: var(--text-primary);
  font-weight: 500;
  border: 0.5px solid var(--border);
}

/* Avatars */
.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 500;
  flex-shrink: 0;
}
.avatar-self { background: var(--bg-accent); color: var(--text-accent); }
.avatar-other { background: var(--fill-control); color: var(--text-primary); }

/* Progress bar */
.progress { height: 4px; background: var(--surface-1); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--text-accent); border-radius: 2px; transition: width 200ms ease; }

/* Skeletons */
.skeleton {
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--fill-control) 50%, var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 4px;
  height: 12px;
  display: inline-block;
}
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Error banner */
.error-banner {
  background: var(--bg-danger);
  color: var(--text-danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Utility */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }

/* Static data notice banner */
.static-data-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: color-mix(in srgb, var(--text-accent) 8%, transparent);
  border: 0.5px solid color-mix(in srgb, var(--text-accent) 30%, transparent);
  border-radius: var(--radius-card);
  padding: 10px 14px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}
.static-data-banner .ti { flex-shrink: 0; color: var(--text-accent); margin-top: 1px; }

/* Bulk action bar */
.bulk-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-card);
  padding: 10px 14px;
}

/* Selected table row */
.table-row.row-selected {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* Danger button */
.btn-danger {
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: var(--radius-btn);
  padding: 8px 16px;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
}
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }
.ml-auto { margin-left: auto; }
.w-full { width: 100%; }
.flex-1 { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* Dialog / Modal */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-4);
}
.dialog {
  background: var(--surface-0);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-card);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-6);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}
.dialog-title {
  font-family: var(--font-voice);
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
}
.dialog-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
}
.dialog-close:hover { background: var(--surface-1); color: var(--text-primary); }
.dialog-body { display: flex; flex-direction: column; gap: var(--space-4); }
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }

/* Phone input with country prefix */
.phone-input-group {
  display: flex;
  align-items: center;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.phone-prefix {
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-1);
  border-right: 0.5px solid var(--border);
  white-space: nowrap;
}
.phone-input {
  border: none !important;
  border-radius: 0 !important;
  flex: 1;
}

/* Customer search dropdown */
.customer-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  margin-top: 4px;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.customer-dropdown-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 0.5px solid var(--border);
}
.customer-dropdown-item:last-child { border-bottom: none; }
.customer-dropdown-item:hover { background: var(--surface-1); }
.selected-customer-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border: 0.5px solid var(--border-accent);
  border-radius: var(--radius);
  padding: 6px 10px;
}

@media (max-width: 639px) {
  .dialog { max-width: 100%; padding: var(--space-4); }
  .form-row { grid-template-columns: 1fr; }
}

/* Grid helpers */
.grid { display: grid; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.grid-2x2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Responsive */
@media (max-width: 1023px) {
  .page-content { padding: var(--space-4); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .hide-tablet { display: none !important; }
}

@media (max-width: 639px) {
  .page-content { padding: var(--space-4); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-2x2 { grid-template-columns: 1fr; }
  .hide-mobile { display: none !important; }
  .table-head { display: none; }
}
