/* ============================================================
   Envios — Apple-inspired design system
   Clean · Minimal · Premium
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  /* Neutrals (macOS-inspired) */
  --bg:        #f5f5f7;         /* macOS window background */
  --bg-alt:    #ffffff;
  --surface:   #ffffff;
  --surface-2: #fafafa;
  --border:    rgba(0,0,0,.08);
  --border-2:  rgba(0,0,0,.12);
  --hairline:  rgba(0,0,0,.05);

  /* Text */
  --text:       #1d1d1f;        /* Apple primary */
  --text-muted: #6e6e73;        /* Apple secondary */
  --text-dim:   #86868b;        /* Apple tertiary */

  /* Accent (Apple blue) */
  --brand:      #0071e3;
  --brand-hover:#0077ED;
  --brand-soft: rgba(0,113,227,.1);

  /* System colors */
  --success: #34c759;
  --warning: #ff9f0a;
  --danger:  #ff3b30;
  --info:    #5ac8fa;

  /* Radius */
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 18px;
  --radius-xl: 22px;

  /* Shadows (very soft, like macOS) */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.03);
  --shadow:    0 6px 20px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-lg: 0 20px 50px rgba(0,0,0,.10), 0 4px 12px rgba(0,0,0,.05);

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Layout */
  --nav-h: 56px;
  --sidebar-w: 236px;
}

* { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  letter-spacing: -0.011em;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
h1 { font-size: 2rem; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.3rem; }
h4 { font-size: 1.15rem; }
h5 { font-size: 1rem; }
h6 { font-size: .925rem; }
p  { color: var(--text-muted); }
small, .small { font-size: .825rem; }
.text-muted { color: var(--text-muted) !important; }

/* ---------- Top nav (Apple-style glass bar) ---------- */
.navbar {
  background: rgba(255, 255, 255, 0.82) !important;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
  height: var(--nav-h);
  padding: 0 1rem;
}
.navbar .navbar-brand {
  color: var(--text) !important;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.navbar .btn, .navbar .dropdown-toggle {
  color: var(--text) !important;
  background: transparent !important;
  border: none !important;
}
.navbar .btn:hover, .navbar .dropdown-toggle:hover { color: var(--brand) !important; }
.navbar.bg-primary { background: rgba(255, 255, 255, 0.82) !important; }

/* ---------- Sidebar ---------- */
.app-shell { display: flex; min-height: calc(100vh - var(--nav-h)); }
.app-sidebar {
  width: var(--sidebar-w);
  background: transparent;
  border-right: 1px solid var(--hairline);
  min-height: calc(100vh - var(--nav-h));
  position: sticky;
  top: var(--nav-h);
  align-self: flex-start;
  overflow-y: auto;
  padding: 1rem .5rem;
}
.app-sidebar .nav-link {
  color: var(--text-muted);
  border-radius: 8px;
  padding: .5rem .75rem;
  margin-bottom: 2px;
  font-weight: 500;
  font-size: .9rem;
  transition: all .15s;
  display: flex; align-items: center;
  letter-spacing: -0.01em;
}
.app-sidebar .nav-link:hover {
  background: rgba(0,0,0,.04);
  color: var(--text);
}
.app-sidebar .nav-link.active {
  background: rgba(0,113,227,.1);
  color: var(--brand);
  font-weight: 600;
}
.app-sidebar .nav-link.active i { color: var(--brand); }

.app-main { flex: 1; min-width: 0; }
.app-main .container-fluid { max-width: 1240px; padding: 1.5rem 1.75rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-header {
  background: transparent !important;
  border-bottom: 1px solid var(--hairline);
  padding: 1rem 1.25rem;
  font-weight: 600;
}
.card-body { padding: 1.25rem; }
.shadow-sm { box-shadow: var(--shadow-sm) !important; }

/* ---------- Buttons ---------- */
.btn {
  border-radius: 980px;              /* Apple pill buttons */
  font-weight: 500;
  letter-spacing: -0.01em;
  padding: .45rem 1.15rem;
  font-size: .9rem;
  transition: all .15s ease;
  border: 1px solid transparent;
}
.btn-lg { padding: .625rem 1.5rem; font-size: .95rem; }
.btn-sm { padding: .3rem .75rem; font-size: .82rem; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  transform: translateY(-0.5px);
  box-shadow: 0 4px 12px rgba(0,113,227,.25);
}
.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.btn-success:hover { background: #2fb34e; border-color: #2fb34e; box-shadow: 0 4px 12px rgba(52,199,89,.3); }

.btn-danger  { background: var(--danger);  border-color: var(--danger);  color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }

.btn-outline-primary {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
}
.btn-outline-primary:hover { background: var(--brand-soft); color: var(--brand); }

.btn-outline-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-2);
}
.btn-outline-secondary:hover { background: rgba(0,0,0,.04); color: var(--text); border-color: var(--border-2); }

.btn-outline-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-outline-danger:hover { background: rgba(255,59,48,.08); color: var(--danger); }

.btn-light {
  background: rgba(0,0,0,.05);
  border: none;
  color: var(--text);
}
.btn-light:hover { background: rgba(0,0,0,.08); color: var(--text); }

.btn-link {
  color: var(--brand);
  text-decoration: none;
  font-weight: 500;
}
.btn-link:hover { color: var(--brand-hover); }

/* ---------- Forms ---------- */
.form-label {
  font-size: .825rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: .3rem;
  letter-spacing: -0.01em;
}
.form-control, .form-select {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: .375rem .75rem;
  font-size: .9rem;
  line-height: 1.35;
  color: var(--text);
  font-family: var(--font);
  transition: border-color .12s, box-shadow .12s, background .12s;
}
.form-control::placeholder { color: var(--text-dim); }
.form-control:hover, .form-select:hover { border-color: rgba(0,0,0,.2); }
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(0,113,227,.15);
  background: var(--surface);
  outline: none;
}
.form-control-lg, .form-select-lg { padding: .5rem .9rem; font-size: .95rem; border-radius: 9px; }
.form-control-sm, .form-select-sm { padding: .25rem .6rem; font-size: .8rem; border-radius: 6px; }

.input-group-text {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text-muted);
  font-weight: 500;
  font-size: .85rem;
  padding: .375rem .7rem;
}

.required-field::after { content: ""; }       /* remove red asterisk, keep label subtle */
.required-field { position: relative; }
.required-field::before { content: ""; }

/* ---------- Tables ---------- */
.table {
  --bs-table-bg: transparent;
  font-size: .925rem;
  color: var(--text);
  margin-bottom: 0;
}
.table > :not(caption) > * > * { padding: .85rem .75rem; border-color: var(--hairline); }
.table > thead { background: var(--surface-2); }
.table > thead > tr > th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--hairline);
}
.table-hover > tbody > tr:hover > * { background: rgba(0,0,0,.025); --bs-table-accent-bg: transparent; }
.table-light th { background: var(--surface-2) !important; }

/* ---------- Badges / pills ---------- */
.badge {
  font-weight: 500;
  font-size: .72rem;
  letter-spacing: 0;
  padding: .35rem .65rem;
  border-radius: 999px;
}
.bg-success   { background: rgba(52,199,89,.15) !important; color: #1e824c !important; }
.bg-warning   { background: rgba(255,159,10,.15) !important; color: #b15f00 !important; }
.bg-danger    { background: rgba(255,59,48,.15) !important; color: #c23127 !important; }
.bg-secondary { background: rgba(0,0,0,.07) !important;     color: var(--text-muted) !important; }

.bg-primary-subtle   { background: rgba(0,113,227,.10) !important; }
.bg-success-subtle   { background: rgba(52,199,89,.12) !important; }
.bg-info-subtle      { background: rgba(90,200,250,.15) !important; }
.bg-warning-subtle   { background: rgba(255,159,10,.15) !important; }
.bg-secondary-subtle { background: rgba(0,0,0,.06) !important; }
.text-primary { color: var(--brand) !important; }
.text-success { color: #1e824c !important; }
.text-warning { color: #b15f00 !important; }
.text-danger  { color: #c23127 !important; }

/* ---------- Stat cards ---------- */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: transform .18s, box-shadow .18s;
}
.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm) !important;
}
.stat-label {
  text-transform: none;
  font-size: .78rem;
  letter-spacing: -0.005em;
  color: var(--text-muted);
  font-weight: 500;
}
.stat-value {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
  margin-top: .25rem;
  letter-spacing: -0.025em;
}
.stat-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
}

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  background: linear-gradient(180deg, #fbfbfd 0%, #f5f5f7 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.login-wrap { width: 100%; max-width: 420px; }
.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2.25rem;
  box-shadow: var(--shadow-lg) !important;
  border: 1px solid var(--hairline);
}
.brand-icon {
  width: 64px; height: 64px; margin: 0 auto;
  background: linear-gradient(135deg, #0071e3, #42a5f5);
  color: #fff; border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem;
  box-shadow: 0 10px 30px rgba(0,113,227,.25);
}

.login-logo {
  display: block;
  margin: 0 auto;
  max-width: 190px;
  max-height: 96px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.form-floating > .form-control, .form-floating > .form-select {
  border-radius: 10px;
  border-color: var(--border-2);
}
.form-floating > label { color: var(--text-muted); padding-left: 1rem; }

/* ---------- Alerts ---------- */
.alert {
  border: none;
  border-radius: var(--radius);
  padding: .85rem 1.1rem;
  font-size: .9rem;
}
.alert-success { background: rgba(52,199,89,.1); color: #1e824c; }
.alert-danger  { background: rgba(255,59,48,.1); color: #c23127; }
.alert-warning { background: rgba(255,159,10,.1); color: #b15f00; }

/* ---------- Modals / offcanvas ---------- */
.offcanvas, .modal-content {
  border-radius: var(--radius-lg);
  border: 1px solid var(--hairline);
  background: var(--surface);
}
.offcanvas-header {
  background: transparent !important;
  border-bottom: 1px solid var(--hairline);
  color: var(--text) !important;
}
.offcanvas-header .btn-close-white { filter: invert(1) brightness(0) opacity(.5); }

/* ---------- Pagination ---------- */
.pagination .page-link {
  border: none;
  color: var(--text-muted);
  background: transparent;
  border-radius: 8px !important;
  margin: 0 2px;
  min-width: 34px;
  text-align: center;
}
.pagination .page-link:hover { background: rgba(0,0,0,.05); color: var(--text); }
.pagination .page-item.active .page-link {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,113,227,.25);
}

/* ---------- Misc compatibility ---------- */
.step-badge {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
  font-size: .75rem;
  margin-right: .5rem;
}
.totals-box {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}
.totals-box .row-line {
  display: flex; justify-content: space-between;
  padding: .4rem 0;
  border-bottom: 1px solid var(--hairline);
  color: var(--text-muted);
  font-size: .9rem;
}
.totals-box .row-line:last-child { border-bottom: none; }
.totals-box .row-line strong { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.totals-box .grand {
  font-size: 1.1rem; font-weight: 600;
  color: var(--text);
  border-top: 1px solid var(--border-2);
  margin-top: .35rem;
  padding-top: .65rem;
}
.totals-box .grand strong { color: var(--brand); font-weight: 700; }

/* Item row (fallback for dm5) */
.item-row {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: .85rem;
  margin-bottom: .55rem;
}

/* Signature */
.signature-wrap {
  border: 1px dashed var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  position: relative;
  overflow: hidden;
}
.signature-wrap canvas { width: 100%; height: 180px; display: block; touch-action: none; }
.signature-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: .88rem;
  pointer-events: none;
}

/* Photo grid (default) */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: .6rem;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .remove-btn {
  position: absolute; top: 6px; right: 6px;
  background: rgba(0,0,0,.7); color: #fff;
  border: none; border-radius: 50%;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: .8rem;
  backdrop-filter: blur(10px);
}

/* Responsive */
@media (max-width: 991.98px) {
  .app-main .container-fluid { padding: 1.15rem 1.25rem; }
}
@media (max-width: 767.98px) {
  .app-shell { display: block; }
  .app-sidebar { display: none; }
  .stat-value { font-size: 1.4rem; }
  html, body { overflow-x: hidden; }
  .app-main .container-fluid { padding: 1rem; max-width: 100%; }
  /* Prevent iOS from auto-zooming on inputs */
  input[type="text"], input[type="email"], input[type="tel"],
  input[type="number"], input[type="date"], input[type="password"],
  select, textarea { font-size: 16px; }
}
@media (max-width: 575.98px) {
  .login-card { padding: 2rem 1.5rem; }
  .app-main .container-fluid { padding: .85rem; }
  .navbar .navbar-brand { font-size: .9rem; }
  .navbar .navbar-brand span { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Print */
@media print {
  .app-sidebar, .navbar, .no-print { display: none !important; }
  .app-main { padding: 0 !important; }
  body { background: #fff; }
}
