:root {
  color-scheme: light;
  --bg: #f3f8fa;
  --panel: #ffffff;
  --panel-soft: #f8fbfc;
  --line: #d7e6ea;
  --line-strong: #bad2d8;
  --text: #071a35;
  --muted: #607382;
  --navy: #071a35;
  --teal: #00869a;
  --teal-dark: #006b7a;
  --teal-soft: #e4f7f9;
  --cyan: #20b8c8;
  --warn: #b76518;
  --warn-soft: #fff3e6;
  --bad: #a51f33;
  --bad-soft: #fde9ed;
  --good: #13733a;
  --good-soft: #e5f6ea;
  --shadow: 0 14px 38px rgba(7, 26, 53, 0.09);
  --shadow-soft: 0 8px 22px rgba(7, 26, 53, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, #f7fbfc 0%, var(--bg) 46%, #eef7f9 100%),
    repeating-linear-gradient(135deg, rgba(0, 134, 154, 0.045) 0 1px, transparent 1px 22px);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--navy);
  cursor: pointer;
  padding: 0 13px;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

button:hover {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 134, 154, 0.09);
}

#new-client-button,
#refresh-button,
#show-overdue,
#save-detail,
#save-new-client {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  font-weight: 700;
}

#refresh-button,
#show-overdue {
  background: #fff;
  color: var(--teal-dark);
}

.secondary-button {
  background: #fff;
  color: var(--teal-dark);
}

#new-client-button:hover,
#save-detail:hover,
#save-new-client:hover {
  background: var(--teal-dark);
}

input,
select,
textarea {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

textarea {
  padding: 9px 10px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 134, 154, 0.1);
  outline: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 20px;
  border-bottom: 1px solid rgba(186, 210, 216, 0.8);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.98), rgba(244, 251, 252, 0.96)),
    repeating-linear-gradient(90deg, rgba(0, 134, 154, 0.05) 0 1px, transparent 1px 24px);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 152px;
  height: 72px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 22px rgba(7, 26, 53, 0.08);
}

.brand-kicker {
  margin: 0 0 2px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.current-user {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  color: var(--navy);
  font-size: 22px;
  font-weight: 900;
}

h2 {
  color: var(--navy);
  font-size: 16px;
  font-weight: 900;
}

h3 {
  color: var(--navy);
  font-size: 15px;
  font-weight: 800;
}

#sync-state {
  color: var(--muted);
  margin-top: 2px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 16px;
  padding: 16px 20px 24px;
}

body:not(.authenticated) .layout,
body:not(.authenticated) .top-actions {
  display: none;
}

body.authenticated .auth-screen {
  display: none;
}

.auth-screen {
  min-height: calc(100vh - 110px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 390px);
  display: grid;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(0, 134, 154, 0.1), transparent 48%),
    #fff;
  box-shadow: var(--shadow);
}

.login-logo {
  width: min(100%, 260px);
  height: auto;
  justify-self: center;
  border-radius: 8px;
}

.login-card h2 {
  margin: 0;
  color: var(--navy);
  font-size: 24px;
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: var(--bad);
  font-size: 13px;
  font-weight: 700;
}

.main-column,
.side-column {
  display: grid;
  align-content: start;
  gap: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}

.stat,
.sales-panel,
.workband,
.clients-section,
.detail,
.tasks {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.stat {
  position: relative;
  overflow: hidden;
  padding: 13px;
}

.stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  background: var(--teal);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 6px;
  color: var(--navy);
  font-size: 25px;
  font-weight: 900;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 251, 252, 0.96));
  border-radius: 8px 8px 0 0;
}

.sales-current {
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.sales-body {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.sales-total {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(0, 134, 154, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(228, 247, 249, 0.92), rgba(255, 255, 255, 0.98)),
    repeating-linear-gradient(135deg, rgba(0, 134, 154, 0.08) 0 1px, transparent 1px 16px);
  padding: 13px;
}

.sales-total span,
.sales-total small,
.sales-row small {
  color: var(--muted);
  font-size: 12px;
}

.sales-total strong {
  display: block;
  margin: 6px 0;
  color: var(--teal-dark);
  font-size: 26px;
  font-weight: 900;
}

.sales-months {
  display: grid;
  gap: 8px;
}

.sales-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 7px 10px;
}

.sales-row span {
  color: var(--navy);
  font-weight: 800;
}

.sales-row strong {
  color: var(--teal-dark);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.filters input {
  width: 210px;
}

.queue {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  padding: 12px;
}

.queue-item,
.task-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.queue-item {
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.queue-item:hover {
  border-color: var(--teal);
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  background: #eef5f7;
  color: #3f5964;
  font-size: 12px;
  font-weight: 700;
}

.pill.due {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.won {
  background: var(--good-soft);
  color: var(--good);
}

.pill.lost,
.pill.lost_to_competitor,
.pill.no_answer {
  background: var(--bad-soft);
  color: var(--bad);
}

.pill.contact,
.pill.proposal_sent,
.pill.demo,
.pill.ready_to_buy {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.pill.pause {
  background: var(--warn-soft);
  color: var(--warn);
}

.table-wrap {
  overflow: auto;
  max-height: 54vh;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7fbfc;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.active {
  background: #eefbfc;
}

.client-name {
  color: var(--navy);
  font-weight: 900;
}

.client-contact {
  color: var(--muted);
  margin-top: 4px;
  font-size: 12px;
}

.detail {
  min-height: 320px;
  padding: 14px;
}

.detail-empty {
  color: var(--muted);
}

.create-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.form-field {
  display: grid;
  gap: 5px;
}

.form-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.form-field textarea {
  min-height: 86px;
  resize: vertical;
}

.wide,
.form-actions {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.danger-button {
  border-color: #d6a1aa;
  color: var(--bad);
}

.danger-button:hover {
  border-color: var(--bad);
  background: var(--bad-soft);
}

.team-admin,
.password-panel {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.compact-form {
  grid-template-columns: 1fr;
}

.team-list {
  display: grid;
  gap: 8px;
}

.team-user {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.team-user strong,
.team-user span {
  display: block;
}

.team-user span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.team-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.form-message {
  min-height: 18px;
  margin: 0;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 700;
}

.tasks {
  overflow: hidden;
}

#tasks {
  display: grid;
  gap: 10px;
  max-height: 36vh;
  overflow: auto;
  padding: 12px;
}

.task-item.done {
  opacity: 0.68;
}

.empty {
  color: var(--muted);
  padding: 12px;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-column {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    display: grid;
    align-items: start;
  }

  .topbar,
  .layout {
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand-logo {
    width: 128px;
    height: 60px;
  }

  h1 {
    font-size: 18px;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .sales-body,
  .sales-row,
  .create-form {
    grid-template-columns: 1fr;
  }

  .section-head {
    display: grid;
    align-items: stretch;
  }

  .filters {
    justify-content: stretch;
  }

  .filters input,
  .filters select {
    width: 100%;
  }
}

@media (max-width: 760px) {
  body {
    background: #f3f8fa;
  }

  button,
  input,
  select,
  textarea {
    min-height: 44px;
  }

  button {
    padding: 0 10px;
  }

  .topbar {
    position: static;
    gap: 10px;
    padding: 10px;
  }

  .brand {
    gap: 9px;
    width: 100%;
  }

  .brand-logo {
    width: 86px;
    height: 42px;
    border-radius: 6px;
    box-shadow: none;
  }

  .brand-kicker,
  #sync-state {
    display: none;
  }

  h1 {
    font-size: 16px;
    line-height: 1.15;
  }

  h2 {
    font-size: 15px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }

  .current-user {
    grid-column: 1 / -1;
    justify-content: center;
    min-height: 34px;
  }

  .layout {
    gap: 10px;
    padding: 10px;
  }

  .main-column,
  .side-column {
    gap: 10px;
  }

  .auth-screen {
    min-height: calc(100vh - 62px);
    padding: 12px;
  }

  .login-card {
    padding: 18px;
  }

  .login-logo {
    width: min(100%, 210px);
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat {
    padding: 10px;
  }

  .stat strong {
    font-size: 22px;
  }

  .section-head {
    min-height: 0;
    padding: 10px;
  }

  .sales-current {
    text-align: left;
  }

  .sales-body,
  .queue,
  #tasks {
    padding: 10px;
  }

  .sales-total strong {
    font-size: 24px;
  }

  .sales-row {
    gap: 4px;
  }

  .queue {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: none;
    overflow: visible;
    padding: 10px;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tbody tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow-soft);
    overflow: hidden;
  }

  tbody tr:hover,
  tbody tr.active {
    background: #eefbfc;
  }

  td {
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    min-height: 40px;
    border-bottom: 1px solid var(--line);
    padding: 9px 10px;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
  }

  .client-name,
  .client-contact {
    overflow-wrap: anywhere;
  }

  .detail {
    min-height: 0;
    padding: 12px;
  }

  .create-form {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .form-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .team-user {
    display: grid;
  }

  .team-actions {
    justify-content: stretch;
  }

  .team-actions button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .top-actions {
    grid-template-columns: 1fr;
  }

  td {
    grid-template-columns: 88px minmax(0, 1fr);
  }
}
