/* ===========================================================
   Property CRM - design tokens
   =========================================================== */
:root {
  --ink:        #1C1B19;
  --ink-soft:   #5B5952;
  --ink-faint:  #918E85;
  --paper:      #F7F5F1;
  --surface:    #FFFFFF;
  --line:       #E6E2D9;
  --line-strong:#D3CDBF;

  --slate:      #0F3D2E;
  --slate-soft: #17503E;
  --slate-line: #1F6350;

  --clay:       #2E8B57;
  --clay-soft:  #DCEEE2;
  --clay-text:  #1F6B47;

  --ok:         #3E7A4E;
  --ok-bg:      #E6F0E7;
  --danger:     #B4432F;
  --danger-bg:  #F6E6E1;

  --radius-sm:  4px;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow: 0 1px 3px rgba(28,27,25,0.05), 0 1px 2px rgba(28,27,25,0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

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

h1, h2, h3 {
  font-family: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 600;
  margin: 0 0 0.5em;
  letter-spacing: -0.015em;
}
h1 { font-size: 23px; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }

/* ===========================================================
   App shell: top mega menu + content
   =========================================================== */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  background: var(--slate);
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: relative;
  z-index: 40;
}

.topbar .brand {
  font-family: "Space Grotesk", sans-serif;
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  margin-right: 32px;
  white-space: nowrap;
}
.topbar .brand .brand-tag { display:block; color:#8B95A5; font-size:11px; font-weight:400; }

.megamenu {
  display: flex;
  align-items: stretch;
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
  height: 100%;
}

.megamenu > li {
  position: relative;
  display: flex;
  align-items: center;
}

.megamenu > li > a,
.megamenu > li > button {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 16px;
  color: #C3CAD5;
  font-family: "Space Grotesk", sans-serif;
  font-size: 13.5px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.megamenu > li > a:hover,
.megamenu > li > button:hover,
.megamenu > li.open > button {
  color: #fff;
  text-decoration: none;
  background: var(--slate-soft);
}

.megamenu > li.active > a {
  color: #fff;
  box-shadow: inset 0 -2px 0 var(--clay);
}

.mega-panel {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 8px 20px rgba(28,27,25,0.12);
  padding: 18px 20px;
  gap: 28px;
  min-width: 620px;
  z-index: 50;
}

.megamenu > li.open .mega-panel {
  display: flex;
}

.mega-col-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-faint);
  margin-bottom: 8px;
}

.mega-col a {
  display: block;
  padding: 5px 0;
  color: var(--ink);
  font-size: 13.5px;
}
.mega-col a:hover { color: var(--clay-text); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #C3CAD5;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius);
}
.user-chip:hover { background: var(--slate-soft); }

.user-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(28,27,25,0.12);
  min-width: 160px;
  z-index: 50;
  padding: 6px;
}
.topbar-right.open .user-menu { display: block; }
.user-menu a { display:block; padding: 8px 10px; border-radius: var(--radius); color: var(--ink); font-size: 13.5px; }
.user-menu a:hover { background: var(--paper); text-decoration: none; }

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--clay-soft);
  color: var(--clay-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 11px;
}

.main { flex: 1; min-width: 0; }
.content { padding: 24px; max-width: 1080px; margin: 0 auto; }

/* ===========================================================
   Components
   =========================================================== */
.btn {
  font-family: "Space Grotesk", sans-serif;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--slate);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--slate-soft); text-decoration: none; }

.btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.btn.secondary:hover { background: var(--surface); border-color: var(--ink-faint); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.master-card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  display: block;
}
.master-card:hover { border-color: var(--clay); text-decoration: none; }
.master-card .master-card-title { color: var(--ink); font-weight: 600; font-size: 14px; }
.master-card .master-card-hint { color: var(--ink-faint); font-size: 12px; margin-top: 2px; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 10px 12px; font-size: 13.5px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-weight: 600; font-size: 13px; background: var(--paper); }
tbody tr:hover { background: #FBFAF8; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 100px; font-size: 12px; font-weight: 600; }
.pill.active   { background: var(--ok-bg); color: var(--ok); }
.pill.inactive { background: var(--danger-bg); color: var(--danger); }

label { display: block; font-weight: 600; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 4px; }

input[type=text], input[type=email], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%;
  max-width: 420px;
  padding: 9px 10px;
  margin-bottom: 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-soft);
}
input:read-only { background: var(--paper); color: var(--ink-faint); }
input[type=checkbox] { width: auto; margin-bottom: 0; }

.msg { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13.5px; }
.msg.success { background: var(--ok-bg); color: var(--ok); }
.msg.error   { background: var(--danger-bg); color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-8px); }
}
.toast {
  position: fixed;
  top: 76px;
  right: 24px;
  z-index: 100;
  background: var(--ok-bg);
  color: var(--ok);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(28,27,25,0.15);
  animation: toast-in 0.25s ease-out;
}
.toast.fade-out { animation: toast-out 0.25s ease-in forwards; }

/* Small motion touches */
.btn { transition: background 0.15s ease, transform 0.1s ease; }
.btn:active { transform: scale(0.97); }
.card { transition: border-color 0.15s ease; }
tbody tr { transition: background 0.1s ease; }
.pill { transition: opacity 0.15s ease; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}
.form-grid .form-field.span-2 { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { max-width: none; }

.icon { width: 15px; height: 15px; display: inline-block; vertical-align: -2px; margin-right: 5px; }
.master-card-icon { width: 22px; height: 22px; color: var(--clay-text); margin-bottom: 8px; display: block; }

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

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 13.5px;
}

/* ===========================================================
   Login page (standalone, no sidebar)
   =========================================================== */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(28,27,25,0.08);
  padding: 32px 32px 28px;
  width: 340px;
}

.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .login-sub { color: var(--ink-faint); font-size: 13px; margin-bottom: 20px; }
.login-card .btn { width: 100%; justify-content: center; }

/* ===========================================================
   Mobile responsiveness
   =========================================================== */

.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  margin-left: auto;
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
}

/* Tables scroll within their own card on narrow screens rather than
   breaking the page layout */
.card:has(table) { overflow-x: auto; }

@media (max-width: 860px) {
  .mega-panel { min-width: 320px; }
}

@media (max-width: 768px) {
  .topbar { padding: 0 14px; }
  .topbar .brand { margin-right: auto; font-size: 15px; }
  .hamburger { display: flex; }

  .megamenu {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--slate);
    height: auto;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    padding-bottom: 8px;
    z-index: 60;
  }
  .megamenu.open { display: flex; }

  .megamenu > li {
    display: block;
    height: auto;
    border-bottom: 1px solid var(--slate-line);
  }
  .megamenu > li > a,
  .megamenu > li > button {
    height: auto;
    padding: 14px 18px;
    width: 100%;
    justify-content: flex-start;
  }

  .mega-panel {
    position: static;
    display: none;
    box-shadow: none;
    border: none;
    border-radius: 0;
    background: var(--slate-soft);
    flex-direction: column;
    gap: 4px;
    padding: 8px 18px 14px;
    min-width: 0;
  }
  .megamenu > li.open .mega-panel { display: flex; }
  .mega-col-label { color: #8B95A5; margin-top: 10px; }
  .mega-col a { color: #E4E8EE; padding: 8px 0; }

  .topbar-right { margin-left: 10px; }
  .user-chip span { display: none; } /* keep just the avatar on very small screens */

  .content { padding: 16px; }

  .form-grid { grid-template-columns: 1fr; }
  .form-grid .form-field.span-2 { grid-column: 1; }

  input, select, textarea { max-width: none; }

  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }

  h1 { font-size: 19px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

@media (max-width: 420px) {
  .login-card { width: 92vw; padding: 26px 20px; }
  .topbar .brand { font-size: 14px; }
  table th, table td { padding: 8px 8px; font-size: 12.5px; }
}
