:root {
  --bg-dark: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-gradient: linear-gradient(135deg, #2563eb 0%, #0284c7 100%);
  --accent-cyan: #0284c7;
  --success-green: #059669;
  --success-green-bg: #ecfdf5;
  --danger-red: #e11d48;
  --danger-red-bg: #fff1f2;
  --warning-amber: #d97706;
  --warning-amber-bg: #fffbeb;
  --info-blue: #2563eb;
  --info-blue-bg: #eff6ff;
  --radius: 14px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.04), 0 8px 10px -6px rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 20px 30px -10px rgba(37, 99, 235, 0.08);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* LOGIN OVERLAY */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle at top left, #eff6ff 0%, #f8fafc 50%, #e0f2fe 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.login-overlay:not(.active) {
  display: none !important;
}

.login-card {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 20px;
  padding: 44px;
  width: 100%;
  max-width: 450px;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.08);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-header .brand-badge {
  width: 58px;
  height: 58px;
  background: var(--primary-gradient);
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 14px;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.25);
}

.login-header h2 {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.login-header h2 span {
  color: var(--accent-cyan);
}

.login-header p {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

.alert-error {
  background: var(--danger-red-bg);
  border: 1px solid rgba(225, 29, 72, 0.2);
  color: var(--danger-red);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 18px;
  font-weight: 500;
}

.login-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  padding-top: 18px;
}

.login-footer code {
  background: var(--info-blue-bg);
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--primary);
  font-weight: 600;
}

/* APP LAYOUT */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: 280px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  box-shadow: 4px 0 24px rgba(15, 23, 42, 0.02);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
}

.logo-badge {
  width: 44px;
  height: 44px;
  background: var(--primary-gradient);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #fff;
  font-size: 18px;
  box-shadow: 0 8px 16px rgba(37, 99, 235, 0.2);
}

.brand h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.brand h2 span {
  color: var(--accent-cyan);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  transition: var(--transition);
}

.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--info-blue-bg);
  border-left: 4px solid var(--primary);
  color: var(--primary);
}

.nav-item .icon {
  width: 20px;
  height: 20px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg-dark);
  border-radius: var(--radius);
  margin-top: 12px;
  border: 1px solid var(--border-color);
}

.user-profile .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}

.user-info {
  flex: 1;
  overflow: hidden;
}

.user-info h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.user-info p {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.btn-logout {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: var(--transition);
}

.btn-logout:hover {
  color: var(--danger-red);
  background: var(--danger-red-bg);
}

.btn-logout .icon {
  width: 18px;
  height: 18px;
}

/* MAIN CONTENT */
.main-content {
  margin-left: 280px;
  flex: 1;
  padding: 36px 40px;
  max-width: 1600px;
}

/* TOP HEADER */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.header-title h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.header-title p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

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

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

.btn-sm {
  padding: 7px 14px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.btn-cyan {
  background: var(--accent-cyan);
  color: #fff;
}

.btn-cyan:hover {
  filter: brightness(1.1);
}

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

.btn-danger:hover {
  filter: brightness(0.9);
}

/* KPI GRID */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 22px;
  margin-bottom: 32px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-focus);
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.kpi-title {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.kpi-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}

.badge-success {
  background: var(--success-green-bg);
  color: var(--success-green);
  border: 1px solid rgba(5, 150, 105, 0.25);
}

.badge-danger {
  background: var(--danger-red-bg);
  color: var(--danger-red);
  border: 1px solid rgba(225, 29, 72, 0.25);
}

.badge-warning {
  background: var(--warning-amber-bg);
  color: var(--warning-amber);
  border: 1px solid rgba(217, 119, 6, 0.25);
}

.badge-info {
  background: var(--info-blue-bg);
  color: var(--info-blue);
  border: 1px solid rgba(37, 99, 235, 0.25);
}

.badge-cyan {
  background: #e0f2fe;
  color: var(--accent-cyan);
  border: 1px solid rgba(2, 132, 199, 0.25);
}

/* TAB CONTENT SYSTEM */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* LIVE MAP SPLIT */
.dashboard-split {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
}

.team-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  height: 600px;
  box-shadow: var(--shadow-md);
}

.panel-header h3 {
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--text-main);
}

.search-input, .select-input, .form-input {
  width: 100%;
  padding: 11px 16px;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.search-input:focus, .select-input:focus, .form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.team-list {
  flex: 1;
  overflow-y: auto;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-card {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: var(--transition);
}

.user-card:hover {
  background: var(--info-blue-bg);
  border-color: var(--primary);
  transform: translateX(2px);
}

.user-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.user-card-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-main);
}

.user-card-meta {
  font-size: 13px;
  color: var(--text-muted);
}

.map-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}

.map-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.legend {
  display: flex;
  align-items: center;
  gap: 16px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.green { background: var(--success-green); }
.dot.red { background: var(--danger-red); }

/* TABLES */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.table-header h3 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
}

.table-header p {
  font-size: 14px;
  color: var(--text-muted);
}

.table-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
}

.data-table th {
  background: #f1f5f9;
  padding: 14px 18px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
}

.data-table th:first-child { border-top-left-radius: 10px; }
.data-table th:last-child { border-top-right-radius: 10px; }

.data-table td {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
  color: var(--text-main);
}

.data-table tr:hover td {
  background: var(--info-blue-bg);
}

/* SUPER UI CALENDAR */
.calendar-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-md);
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.calendar-title-group h2 {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-main);
}

.calendar-title-group p {
  color: var(--text-muted);
  font-size: 14px;
}

.calendar-nav-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.calendar-legend {
  display: flex;
  gap: 18px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-color);
}

.calendar-grid-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 14px;
  padding-bottom: 14px;
}

.calendar-grid-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
}

.cal-day-cell {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  min-height: 95px;
  padding: 12px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.cal-day-cell:hover {
  background: var(--info-blue-bg);
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.cal-day-cell.other-month {
  opacity: 0.4;
}

.cal-day-number {
  font-weight: 800;
  font-size: 15px;
  color: var(--text-main);
}

.cal-status-pills {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 6px;
}

.cal-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 700;
  text-align: center;
}

.cal-pill.green { background: var(--success-green-bg); color: var(--success-green); border: 1px solid rgba(5, 150, 105, 0.3); }
.cal-pill.red { background: var(--danger-red-bg); color: var(--danger-red); border: 1px solid rgba(225, 29, 72, 0.3); }
.cal-pill.yellow { background: var(--warning-amber-bg); color: var(--warning-amber); border: 1px solid rgba(217, 119, 6, 0.3); }

/* SMART FILTER BAR */
.smart-filter-bar {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.filter-group label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: block;
}

.preset-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill-btn {
  background: #fff;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.pill-btn:hover {
  background: var(--info-blue-bg);
  border-color: var(--primary);
}

.pill-btn.active {
  background: var(--primary-gradient);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.filter-controls-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.control-item label {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

/* VISITS GRID */
.visits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 22px;
  margin-top: 18px;
}

.visit-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.visit-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-focus);
}

.visit-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.visit-customer-name {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-main);
}

.visit-location-badge {
  background: #e0f2fe;
  border: 1px solid rgba(2, 132, 199, 0.25);
  color: var(--accent-cyan);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* MINIMAL SETTINGS */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 36px;
  max-width: 820px;
  box-shadow: var(--shadow-md);
}

.settings-header {
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 18px;
}

.settings-header h3 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
}

.settings-header p {
  color: var(--text-muted);
  font-size: 14px;
}

.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-item label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.help-text {
  font-size: 13px;
  color: var(--text-muted);
}

.checkbox-item {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.checkbox-item input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.settings-actions {
  margin-top: 32px;
}

/* MODALS */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 32px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h3 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 26px;
  cursor: pointer;
  transition: var(--transition);
}

.modal-close:hover {
  color: var(--text-main);
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-main);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 28px;
}

.location-capture-box {
  background: var(--info-blue-bg);
  border: 1px dashed var(--primary);
  padding: 14px;
  border-radius: 10px;
}

.capture-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}

.gps-status {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
