:root {
  color-scheme: light;
  --ink: #181a19;
  --muted: #6d726e;
  --line: #dde0dd;
  --surface: #ffffff;
  --canvas: #f3f4f2;
  --black: #171918;
  --orange: #d86618;
  --orange-soft: #fff0e4;
  --green: #277a4a;
  --green-soft: #e7f4ec;
  --red: #b83b38;
  --shadow: 0 18px 50px rgba(20, 24, 21, 0.12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--ink); }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(17, 20, 18, 0.7), rgba(17, 20, 18, 0.78)),
    url("https://images.unsplash.com/photo-1503387762-592deb58ef4e?auto=format&fit=crop&w=1800&q=85") center/cover;
}

.auth-panel {
  width: min(100%, 430px);
  padding: 34px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-lockup, .brand-button { display: flex; align-items: center; gap: 14px; }
.brand-lockup h1 { margin: 0; font-size: 26px; letter-spacing: 0; }
.brand-lockup p { margin: 4px 0 0; color: var(--muted); }
.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--black);
  color: white;
  border-radius: 6px;
  font-size: 20px;
  font-weight: 800;
}
.brand-mark.small { width: 42px; height: 42px; font-size: 16px; }

.auth-form { display: grid; gap: 17px; margin-top: 32px; }
.portal-home-link {
  display: inline-block;
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
}
.portal-home-link:hover { color: var(--ink); }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cfd3cf;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(24, 26, 25, 0.08); }
textarea { min-height: 92px; resize: vertical; }
.form-error { margin: 0; color: var(--red); font-size: 13px; }

.button {
  min-height: 42px;
  padding: 10px 15px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 750;
}
.button.primary { background: var(--black); color: white; }
.button.secondary { background: white; border-color: #cfd3cf; color: var(--ink); }
.button.danger { background: #fff1f0; border-color: #efc5c2; color: var(--red); }
.button.link { min-height: auto; background: transparent; color: var(--ink); }
.button.wide { width: 100%; }
.portal-site-button { display: grid; place-items: center; text-decoration: none; }
.button:disabled { opacity: 0.5; cursor: not-allowed; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 242px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  background: var(--black);
  color: white;
}
.brand-button {
  width: 100%;
  border: 0;
  padding: 5px 7px 20px;
  background: transparent;
  color: white;
  text-align: left;
}
.brand-button strong, .brand-button small { display: block; }
.brand-button small { margin-top: 3px; color: #aeb4af; }
.brand-button .brand-mark { background: white; color: var(--black); }
.main-nav { display: grid; gap: 4px; }
.nav-button {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 6px;
  padding: 11px 12px;
  background: transparent;
  color: #c9ceca;
  text-align: left;
}
.nav-button:hover, .nav-button.active { background: #2d302e; color: white; }
.nav-icon { text-align: center; font-size: 18px; }
.badge {
  min-width: 21px;
  height: 21px;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--orange);
  color: white;
  font-size: 11px;
  font-weight: 800;
}
.sidebar-footer { margin-top: auto; display: grid; gap: 12px; padding: 12px 6px 2px; }
.sync-state { display: flex; align-items: center; gap: 8px; color: #aeb4af; font-size: 12px; }
#sync-dot { width: 8px; height: 8px; border-radius: 50%; background: #4cc379; }

.workspace { min-width: 0; }
.topbar {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(20px, 4vw, 52px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h2, .modal-header h3 { margin: 2px 0 0; font-size: 26px; letter-spacing: 0; }
.eyebrow { margin: 0; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: white;
  color: var(--ink);
  font-size: 22px;
}
.content { max-width: 1450px; margin: 0 auto; padding: 30px clamp(20px, 4vw, 52px) 70px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; }
.metric {
  min-height: 120px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.metric p { margin: 0; color: var(--muted); font-size: 13px; font-weight: 700; }
.metric strong { display: block; margin-top: 16px; font-size: 28px; letter-spacing: 0; }
.metric small { display: block; margin-top: 7px; color: var(--muted); line-height: 1.35; }

.section { margin-top: 28px; }
.section-header { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 13px; }
.section-header h3 { margin: 0; font-size: 18px; }
.section-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.split-sections { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.status-section {
  min-width: 0;
  padding: 15px;
  border-top: 4px solid var(--orange);
  background: var(--orange-soft);
}
.status-section.complete { border-color: var(--green); background: var(--green-soft); }
.status-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.status-heading h3 { margin: 0; font-size: 17px; }
.status-heading span { color: var(--muted); font-weight: 800; }

.item-list { display: grid; gap: 9px; }
.item-card {
  width: 100%;
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 16px;
  background: white;
  color: var(--ink);
  text-align: left;
}
button.item-card:hover { border-color: #a7ada8; box-shadow: 0 5px 18px rgba(20, 24, 21, 0.07); }
.item-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.item-title { margin: 0; font-size: 16px; font-weight: 800; overflow-wrap: anywhere; }
.item-subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.item-meta { display: flex; flex-wrap: wrap; gap: 12px 18px; color: var(--muted); font-size: 12px; }
.item-meta strong { color: var(--ink); }
.status-pill {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  padding: 5px 9px;
  border-radius: 12px;
  background: var(--orange-soft);
  color: #a94c10;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}
.status-pill.complete, .status-pill.paid { background: var(--green-soft); color: var(--green); }
.status-pill.dark { background: #eceeec; color: var(--ink); }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.search { max-width: 420px; }
.team-filter { max-width: 250px; }
.empty-state { padding: 38px 20px; border: 1px dashed #c8ccc8; text-align: center; color: var(--muted); background: rgba(255,255,255,.55); }
.empty-state strong { display: block; margin-bottom: 5px; color: var(--ink); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); background: white; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
th { color: var(--muted); background: #f8f9f7; font-size: 11px; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, .7fr); gap: 22px; }
.detail-panel { border: 1px solid var(--line); border-radius: 7px; padding: 18px; background: white; }
.detail-panel h4 { margin: 0 0 15px; }
.detail-list { display: grid; grid-template-columns: 150px 1fr; gap: 11px 16px; margin: 0; }
.detail-list dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.detail-list dd { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

.attachment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.attachment {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 14px;
  background: #f8f9f7;
}
.attachment-icon { font-size: 28px; }
.attachment span { color: var(--muted); font-size: 12px; }

.chat-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); min-height: calc(100vh - 220px); border: 1px solid var(--line); background: white; }
.chat-list { border-right: 1px solid var(--line); overflow: auto; }
.chat-contact { width: 100%; display: grid; gap: 4px; padding: 15px; border: 0; border-bottom: 1px solid var(--line); background: white; text-align: left; }
.chat-contact.active { background: #f0f2ef; }
.chat-contact strong { overflow-wrap: anywhere; }
.chat-contact span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-pane { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; }
.chat-header { padding: 14px 17px; border-bottom: 1px solid var(--line); font-weight: 800; }
.messages { display: flex; flex-direction: column; gap: 9px; padding: 18px; overflow-y: auto; background: #f4f5f3; }
.message { max-width: min(70%, 560px); padding: 11px 13px; border-radius: 7px; background: white; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.message.mine { align-self: flex-end; background: #dff1e6; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message small { display: block; margin-top: 6px; color: var(--muted); text-align: right; }
.chat-compose { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-compose input { min-width: 0; }

.modal {
  width: min(720px, calc(100vw - 28px));
  max-height: min(850px, calc(100vh - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(12, 15, 13, 0.55); backdrop-filter: blur(3px); }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 22px; overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.drop-zone { padding: 26px; border: 2px dashed #bfc4bf; border-radius: 7px; text-align: center; color: var(--muted); background: #f8f9f7; }
.drop-zone.dragging { border-color: var(--orange); background: var(--orange-soft); }
.selected-files { display: grid; gap: 6px; margin-top: 10px; font-size: 12px; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: min(460px, calc(100vw - 28px));
  padding: 12px 16px;
  border-radius: 6px;
  background: var(--black);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }
.loading { padding: 50px 20px; text-align: center; color: var(--muted); }
.mobile-nav { display: none; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-sections { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { display: block; padding-bottom: 72px; }
  .sidebar { display: none; }
  .topbar { height: 78px; padding: 13px 16px; }
  .topbar h2 { font-size: 22px; }
  .content { padding: 19px 14px 34px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { min-height: 104px; padding: 14px; }
  .metric strong { font-size: 23px; }
  .mobile-nav {
    position: fixed;
    z-index: 20;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(var(--nav-count, 5), minmax(0, 1fr));
    padding: 7px 5px calc(7px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(16px);
  }
  .mobile-nav .nav-button {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 2px;
    padding: 4px 2px;
    color: var(--muted);
    font-size: 10px;
    text-align: center;
  }
  .mobile-nav .nav-button.active { background: transparent; color: var(--black); }
  .mobile-nav .nav-icon { font-size: 19px; }
  .mobile-nav .badge { position: absolute; transform: translate(11px, -5px); }
  .chat-layout { grid-template-columns: 1fr; min-height: calc(100vh - 190px); }
  .chat-list { display: none; }
  .message { max-width: 86%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .detail-list { grid-template-columns: 1fr; gap: 4px; }
  .detail-list dd { margin-bottom: 8px; }
  .auth-panel { padding: 26px 22px; }
  #primary-action { max-width: 145px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
