/* KroyTech CRM — admin interface.
   Brand: Archivo headings / Inter body, KroyTech green #79b62b, azure #1b9bd7, navy ink. */
:root {
  --green: #79b62b;
  --green-dark: #5f9420;
  --blue: #1b9bd7;
  --blue-dark: #1273a3;
  --ink: #16304f;
  --ink-soft: #33475e;
  --muted: #5c6f82;
  --paper: #ffffff;
  --paper-alt: #f4f6f4;
  --rule: #e2e8ea;
  --navy-band: #12263f;
  --navy-deep: #0d1c30;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(18, 38, 63, 0.08), 0 4px 14px rgba(18, 38, 63, 0.06);
  --font-head: 'Archivo', 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'Inter', 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink-soft);
  background: #eef1f3;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--ink); margin: 0 0 0.6em; }
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- shell ---------- */
.crm-shell { display: flex; min-height: 100vh; }
.crm-side {
  width: 252px; flex: 0 0 252px;
  background: linear-gradient(180deg, var(--navy-band), var(--navy-deep));
  color: #c9d6e2;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.crm-brand { display: block; padding: 20px 22px 14px; background: #fff; }
.crm-brand img { display: block; max-width: 100%; height: auto; }
.crm-nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.crm-nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 6px;
  color: #aebfd2; font-weight: 500; font-size: 14.5px;
}
.crm-nav-link:hover { background: rgba(255,255,255,0.07); color: #fff; text-decoration: none; }
.crm-nav-link.is-active { background: rgba(121,182,43,0.16); color: #fff; box-shadow: inset 3px 0 0 var(--green); }
.crm-nav-link svg { width: 19px; height: 19px; flex: 0 0 19px; }
.crm-side-foot { padding: 16px; border-top: 1px solid rgba(255,255,255,0.1); }
.crm-user { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.crm-user-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head); font-weight: 700; font-size: 17px; flex: 0 0 38px;
}
.crm-user-meta strong { display: block; color: #fff; font-size: 14px; line-height: 1.25; }
.crm-user-meta span { font-size: 12px; color: #8fa3b8; text-transform: capitalize; }
.crm-logout {
  display: inline-flex; align-items: center; gap: 8px;
  color: #aebfd2; font-size: 13.5px; font-weight: 500;
  border: 1px solid rgba(255,255,255,0.18); border-radius: 6px; padding: 7px 12px;
}
.crm-logout:hover { color: #fff; border-color: rgba(255,255,255,0.4); text-decoration: none; }
.crm-logout svg { width: 16px; height: 16px; }

.crm-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.crm-top {
  background: var(--paper); border-bottom: 1px solid var(--rule);
  padding: 14px 28px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 30;
}
.crm-top h1 { font-size: 21px; margin: 0; flex: 1; }
.crm-site-link { font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.crm-burger {
  display: none; background: none; border: 1px solid var(--rule);
  border-radius: 6px; padding: 9px 10px; cursor: pointer;
}
.crm-burger span { display: block; width: 20px; height: 2px; background: var(--ink); margin: 4px 0; border-radius: 2px; }
.crm-content { padding: 26px 28px; max-width: 1240px; width: 100%; margin: 0 auto; flex: 1; }
.crm-foot {
  padding: 14px 28px; font-size: 12.5px; color: var(--muted);
  border-top: 1px solid var(--rule); background: var(--paper);
}
.crm-scrim { display: none; }

/* ---------- cards / stats ---------- */
.card {
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; margin-bottom: 22px;
}
.card h2 { font-size: 17px; margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; position: relative; overflow: hidden;
}
.stat-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--green); }
.stat-card.blue::before { background: var(--blue); }
.stat-card.amber::before { background: #e8a13c; }
.stat-card.red::before { background: #d9534f; }
.stat-num { font-family: var(--font-head); font-size: 30px; font-weight: 800; color: var(--ink); line-height: 1.15; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 2px solid var(--rule);
  white-space: nowrap;
}
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.tbl tbody tr:hover { background: #f7fafc; }
.tbl .rowlink { font-weight: 600; color: var(--ink); }
.tbl .rowlink:hover { color: var(--blue-dark); }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty-note { padding: 26px 12px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.5; white-space: nowrap;
  background: #e8edf1; color: var(--ink-soft);
}
.b-new { background: #e3f2fd; color: #1565c0; }
.b-contacted { background: #e0f2f1; color: #00695c; }
.b-quoted { background: #fff3e0; color: #b26a00; }
.b-won { background: #e8f5e9; color: #2e7d32; }
.b-lost { background: #efebe9; color: #6d4c41; }
.b-open { background: #e3f2fd; color: #1565c0; }
.b-in_progress { background: #fff3e0; color: #b26a00; }
.b-resolved { background: #e8f5e9; color: #2e7d32; }
.b-closed { background: #eceff1; color: #546e7a; }
.b-low { background: #eceff1; color: #546e7a; }
.b-medium { background: #e3f2fd; color: #1565c0; }
.b-high { background: #fff3e0; color: #b26a00; }
.b-urgent { background: #fdecea; color: #c62828; }
.b-admin { background: #16304f; color: #fff; }
.b-staff { background: #e8edf1; color: var(--ink-soft); }
.b-active { background: #e8f5e9; color: #2e7d32; }
.b-expiring { background: #fff3e0; color: #b26a00; }
.b-expired { background: #fdecea; color: #c62828; }
.b-cancelled { background: #eceff1; color: #546e7a; }
.b-pending { background: #e3f2fd; color: #1565c0; }
.b-overdue { background: #fdecea; color: #c62828; }
.b-done { background: #e8f5e9; color: #2e7d32; }
.b-scheduled { background: #e3f2fd; color: #1565c0; }
.b-completed { background: #e8f5e9; color: #2e7d32; }

/* ---------- misc utilities ---------- */
.muted { color: var(--muted); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .inline-form { display: inline-block; margin-left: 6px; }
.row-actions .btn { margin-left: 6px; }
.row-actions .btn:first-child { margin-left: 0; }

/* ---------- site survey visits & photos ---------- */
.visit {
  border-left: 3px solid var(--green);
  padding: 2px 0 2px 16px;
  margin: 0 0 22px;
}
.visit-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.visit-head strong { font-size: 14.5px; }
.visit-notes { white-space: pre-wrap; font-size: 14px; margin: 6px 0 10px; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.photo-grid figure {
  margin: 0; background: #fff;
  border: 1px solid var(--rule); border-radius: 8px; overflow: hidden;
}
.photo-grid img { width: 100%; height: 120px; object-fit: cover; display: block; background: #f1f4f6; }
.photo-grid figcaption { padding: 6px 8px; font-size: 12px; color: var(--ink-soft); }
.photo-grid .photo-actions { display: flex; gap: 6px; padding: 6px 8px 8px; }
.photo-grid .photo-actions input[type="text"] { flex: 1; min-width: 0; font-size: 12px; padding: 5px 8px; }

/* ---------- filter chips ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  display: inline-block; padding: 6px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
  background: #fff; border: 1px solid var(--rule); text-decoration: none;
}
.chip:hover { border-color: var(--green); color: var(--ink); text-decoration: none; }
.chip.is-active { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------- buttons / forms ---------- */
.btn {
  display: inline-block; border: 1px solid transparent; border-radius: 6px;
  padding: 9px 18px; font-size: 14px; font-weight: 600; font-family: var(--font-body);
  cursor: pointer; background: var(--green); color: #fff; line-height: 1.4;
}
.btn:hover { background: var(--green-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; border-color: var(--rule); color: var(--ink-soft); }
.btn-secondary:hover { background: #f4f6f8; color: var(--ink); }
.btn-danger { background: #fff; border-color: #e5a49f; color: #c62828; }
.btn-danger:hover { background: #fdecea; color: #c62828; }
.btn-blue { background: var(--blue); }
.btn-blue:hover { background: var(--blue-dark); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="number"], .field input[type="date"], .field select, .field textarea {
  width: 100%; border: 1px solid #c9d4dc; border-radius: 6px;
  padding: 10px 12px; font-size: 14.5px; font-family: var(--font-body); color: var(--ink-soft);
  background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(27,155,215,0.15);
}
.field textarea { min-height: 110px; resize: vertical; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filters .field { min-width: 170px; }
.inline-form { display: inline; }

/* ---------- alerts ---------- */
.alert { border-radius: 6px; padding: 12px 16px; margin-bottom: 18px; font-size: 14px; border: 1px solid; }
.alert-ok { background: #eef6e4; border-color: #cde9a8; color: #3d6414; }
.alert-err { background: #fdeeee; border-color: #f3c1bd; color: #a02a24; }

/* ---------- detail layout ---------- */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 22px; align-items: start; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; color: var(--ink); font-weight: 500; overflow-wrap: anywhere; }
.action-list { display: flex; flex-direction: column; gap: 10px; }
.action-list .btn { text-align: center; }

/* ---------- pipeline ---------- */
.pipeline { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 6px; }
.pipe-col { background: #f1f4f6; border-radius: var(--radius); padding: 12px; min-height: 180px; }
.pipe-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.pipe-head h3 { font-size: 13.5px; margin: 0; text-transform: capitalize; }
.pipe-head .pipe-total { font-size: 12px; color: var(--muted); font-weight: 600; }
.pipe-count { display: inline-block; min-width: 24px; text-align: center; background: #dbe3ea; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 1px 7px; margin-left: 6px; }
.deal-card {
  background: #fff; border: 1px solid var(--rule); border-radius: 6px;
  padding: 12px 13px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(18,38,63,0.06);
}
.deal-card:hover { border-color: var(--blue); }
.deal-card a.title { font-weight: 600; color: var(--ink); font-size: 14px; display: block; margin-bottom: 4px; }
.deal-card .meta { font-size: 12.5px; color: var(--muted); }
.deal-card .val { font-weight: 700; color: var(--ink); font-size: 13.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }

/* ---------- activity ---------- */
.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-list li { padding: 10px 0 10px 4px; border-bottom: 1px solid var(--rule); font-size: 13.5px; display: flex; gap: 10px; }
.activity-list li:last-child { border-bottom: none; }
.activity-list .a-dot { flex: 0 0 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--green); margin-top: 7px; }
.activity-list .a-time { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: auto; }

/* ---------- login / setup ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, var(--navy-band), var(--navy-deep)); }
.auth-card { background: #fff; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); width: 100%; max-width: 430px; padding: 36px 34px; }
.auth-card .logo-row { text-align: center; margin-bottom: 22px; }
.auth-card .logo-row img { max-width: 210px; height: auto; }
.auth-card h1 { font-size: 20px; text-align: center; margin-bottom: 6px; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }
.auth-card .field { margin-bottom: 16px; }
.auth-card .btn { width: 100%; padding: 12px; font-size: 15px; }
.auth-note { margin-top: 18px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .detail-grid { grid-template-columns: 1fr; }
  .crm-content { padding: 20px 16px; }
  .crm-top { padding: 12px 16px; }
}
@media (max-width: 820px) {
  .crm-side {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 60;
    transform: translateX(-100%); transition: transform 0.25s ease;
    height: 100dvh;
  }
  body.nav-open .crm-side { transform: translateX(0); }
  body.nav-open .crm-scrim { display: block; position: fixed; inset: 0; background: rgba(13,28,48,0.5); z-index: 50; }
  .crm-burger { display: block; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr; }
  .crm-top h1 { font-size: 18px; }
}
