/* No build step. Mobile-first — owners check this from a phone.
   Kept brand-neutral (not AutomateIQ's own black/green) since this same
   stylesheet renders both the superadmin panel and every white-labeled
   tenant portal. */

:root {
  --color-bg: #f4f5fb;
  --color-surface: #ffffff;
  --color-border: #e5e7f0;
  --color-text: #1a1d29;
  --color-muted: #6b7180;
  --color-primary: #4f46e5;
  --color-primary-dark: #4338ca;
  --color-primary-soft: #eef2ff;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --radius: 10px;
  --radius-lg: 14px;
  --nav-width: 220px;
  --topbar-height: 60px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 40, 0.05);
  --shadow-md: 0 4px 14px rgba(20, 22, 40, 0.07);
  --shadow-lg: 0 12px 32px rgba(20, 22, 40, 0.10);

  --sidebar-bg: #14152b;
  --sidebar-bg-alt: #1b1c38;
  --sidebar-text: #c7c9e8;
  --sidebar-text-muted: #7c7ea8;
  --sidebar-active-bg: #292a52;
  --sidebar-active-text: #ffffff;
  --sidebar-accent: #818cf8;
  --sidebar-border: #26274a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-dark); text-decoration: underline; }

/* ---- App shell / nav ---- */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; flex: 1; }
.topbar-user {
  font-size: 14px;
  font-weight: 600;
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  padding: 6px 12px;
  border-radius: 99px;
}

.nav-toggle {
  display: inline-block;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 18px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--color-text);
}

.side-nav {
  display: none;
  flex-direction: column;
  background: var(--sidebar-bg);
  background-image: linear-gradient(180deg, var(--sidebar-bg-alt) 0%, var(--sidebar-bg) 55%);
  border-bottom: 1px solid var(--sidebar-border);
}

.side-nav.open { display: flex; }

.side-nav a {
  padding: 12px 20px;
  color: var(--sidebar-text);
  border-bottom: 1px solid var(--sidebar-border);
  font-size: 14.5px;
  font-weight: 500;
  position: relative;
  transition: background 0.15s ease, color 0.15s ease;
}

.side-nav a.active {
  color: var(--sidebar-active-text);
  background: var(--sidebar-active-bg);
  font-weight: 600;
}

.side-nav a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--sidebar-accent);
}

.side-nav a:hover { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); text-decoration: none; }
.nav-logout { color: #f87171 !important; }
.nav-logout:hover { background: rgba(248, 113, 113, 0.12) !important; color: #fca5a5 !important; }

.content {
  flex: 1;
  padding: 20px 16px 40px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 4px 0 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--color-border);
}

@media (min-width: 860px) {
  .app-shell { flex-direction: row; }
  .nav-toggle { display: none; }
  .topbar { position: fixed; left: var(--nav-width); right: 0; top: 0; }
  .side-nav {
    display: flex;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--nav-width);
    border-right: 1px solid var(--sidebar-border);
    border-bottom: none;
    padding-top: var(--topbar-height);
    box-shadow: var(--shadow-lg);
  }
  .content { margin-left: var(--nav-width); margin-top: var(--topbar-height); max-width: 900px; padding: 28px 24px 48px; }
}

/* ---- Cards / tables ---- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 20px;
  transition: box-shadow 0.15s ease;
}

.card:hover { box-shadow: var(--shadow-md); }

.card h2 {
  margin-top: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  margin-top: 22px;
}

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px 14px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.stat-tile::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-primary), var(--sidebar-accent));
}

.stat-tile .num { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; display: block; color: var(--color-text); }
.stat-tile .label { color: var(--color-muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--color-border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted); font-weight: 700; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--color-primary-soft); }
tbody tr:last-child td { border-bottom: none; }

.table-wrap { overflow-x: auto; }

@media (max-width: 640px) {
  table.stack, table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: 10px; padding: 10px; background: var(--color-surface); box-shadow: var(--shadow-sm); }
  table.stack tr:hover { background: var(--color-surface); }
  table.stack td { border: none; padding: 5px 2px; }
  table.stack td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-muted);
  }
}

/* ---- Badges ---- */

.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; letter-spacing: 0.01em; }
.badge-new { background: #e0e7ff; color: #3730a3; }
.badge-scheduled { background: #dbeafe; color: #1e40af; }
.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-canceled { background: #f3f4f6; color: #6b7280; }
.badge-emergency { background: #fee2e2; color: #991b1b; }
.badge-normal { background: #f3f4f6; color: #4b5563; }

/* ---- Forms ---- */

label { display: block; font-size: 13px; font-weight: 700; margin: 14px 0 5px; color: var(--color-text); }
input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=date], input[type=time], input[type=number], input[type=file],
select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 15px;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

textarea { min-height: 90px; resize: vertical; }

.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 160px; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover { border-color: var(--color-muted); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25); }
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35); }
.btn-danger { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-block { width: 100%; margin-top: 14px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---- Flash / misc ---- */

.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; font-weight: 500; border-left: 3px solid transparent; }
.flash-success { background: #ecfdf3; color: #166534; border-left-color: var(--color-success); }
.flash-error { background: #fef2f2; color: #991b1b; border-left-color: var(--color-danger); }
.flash-info { background: var(--color-primary-soft); color: #3730a3; border-left-color: var(--color-primary); }

.muted { color: var(--color-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }

code {
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 13px;
}

/* ---- Login page ---- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--sidebar-bg);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(129, 140, 248, 0.25), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(79, 70, 229, 0.25), transparent 45%),
    linear-gradient(180deg, var(--sidebar-bg-alt) 0%, var(--sidebar-bg) 100%);
}

.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  margin: 16px;
}

.login-card h1 { margin: 0 0 4px; font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }

/* ---- Calendar ---- */

.cal-table td { vertical-align: top; height: 90px; width: 14.28%; }
.cal-day-num { font-weight: 700; font-size: 13px; }
.cal-job { display: block; font-size: 11px; margin-top: 3px; padding: 2px 4px; border-radius: 4px; background: #dbeafe; color: #1e40af; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-job.emergency { background: #fee2e2; color: #991b1b; }
.cal-today { background: #fffbeb; }
