:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #eef2f6;
  --text: #1f2933;
  --muted: #667085;
  --line: #d8dee8;
  --primary: #1f7a6b;
  --primary-dark: #155d52;
  --accent: #b54708;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  background: #17212b;
  color: #f8fafc;
  padding: 12px 28px;
  box-shadow: 0 8px 26px rgba(31, 41, 51, 0.16);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #b6c2cf;
  font-size: 13px;
  margin-top: 3px;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: auto;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  background: transparent;
  color: #dce5ee;
  text-align: center;
  white-space: nowrap;
}

.nav-item:hover,
.nav-item.active {
  background: #243241;
  color: #ffffff;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: #9fd3c7;
  font-weight: 700;
}

.workspace {
  min-width: 0;
  width: 100%;
  padding: 22px 28px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar-actions,
.current-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.current-user {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.compact-button {
  min-height: 34px;
  padding: 6px 11px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.3;
}

.status-pill,
.count-label {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 8px 12px;
  white-space: nowrap;
}

.section-view {
  display: none;
}

.section-view.active {
  display: block;
}

.subnav {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.subnav-item {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
}

.subnav-item.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.08);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel.active {
  display: block;
}

.form-panel {
  padding: 20px;
}

.list-panel {
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  margin-bottom: 16px;
}

label,
.field-group {
  display: grid;
  gap: 7px;
  margin-bottom: 15px;
  color: #344054;
  font-size: 14px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  padding: 9px 11px;
  color: var(--text);
  background: #ffffff;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(31, 122, 107, 0.16);
}

.field-label {
  color: #344054;
}

.responsavel-picker {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  padding-right: 2px;
}

.picker-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fbfcfe;
}

.picker-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 600;
}

.picker-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-email {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.picker-row input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
}

.single-picker {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fbfcfe;
}

.single-picker input {
  width: 16px;
  height: 16px;
  min-height: 16px;
}

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

.form-grid label,
.form-grid .field-group {
  margin-bottom: 0;
}

.span-2 {
  grid-column: 1 / -1;
}

.wide-panel {
  grid-column: 1 / -1;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 4px;
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
}

.check-field input {
  width: 17px;
  height: 17px;
  min-height: 17px;
  padding: 0;
}

.password-section {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.password-section h2 {
  margin-bottom: 14px;
}

.hidden {
  display: none !important;
}

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

.form-actions.split-actions {
  justify-content: space-between;
}

.primary-button,
.secondary-button,
.icon-button,
.text-button {
  border: 0;
  border-radius: 7px;
  min-height: 38px;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
  padding: 9px 14px;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  padding: 9px 14px;
  font-weight: 700;
}

.secondary-button:hover {
  background: var(--surface-muted);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  padding: 0;
  background: var(--surface-muted);
  color: var(--text);
  font-weight: 800;
}

.icon-button svg,
.icon-link svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.icon-button.success {
  color: var(--primary-dark);
}

.icon-button.warning {
  color: var(--accent);
}

.icon-button.danger {
  color: var(--danger);
}

.icon-link {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  min-height: 38px;
  border-radius: 7px;
  background: var(--surface-muted);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.icon-link:hover {
  background: #e7f5f1;
}

.icon-button:hover,
.icon-link:hover {
  filter: brightness(0.98);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  background: #f8fafc;
  color: #475467;
  font-size: 13px;
  font-weight: 700;
}

td {
  font-size: 14px;
}

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

.actions-col {
  width: 168px;
  text-align: right;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  white-space: nowrap;
}

.email-choice-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(23, 33, 43, 0.42);
}

.email-choice-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.email-choice-options {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.order-items-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.order-items-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.details-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.details-toggle:hover {
  background: var(--surface-muted);
}

.details-toggle svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.order-items-list {
  display: grid;
  gap: 5px;
  margin: 8px 0 0;
  padding-left: 18px;
  max-width: 520px;
}

.order-items-list li {
  line-height: 1.35;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  border-radius: 999px;
  background: #e7f5f1;
  color: #185d52;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.tag.email {
  background: #fff3e6;
  color: var(--accent);
}

.tag.danger-tag {
  background: #fee4e2;
  color: var(--danger);
}

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

.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 36px;
  box-shadow: var(--shadow);
}

.empty-state p {
  color: var(--muted);
  margin-bottom: 0;
}

.order-layout {
  display: grid;
  grid-template-columns: minmax(420px, 0.95fr) minmax(0, 1.05fr);
  gap: 18px;
  align-items: start;
}

.order-form {
  display: block;
}

.line-builder {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.compact-heading {
  align-items: flex-start;
  margin-bottom: 12px;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.line-mode {
  display: none;
}

.line-mode.active {
  display: grid;
}

.lines-table {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.lines-table table {
  min-width: 560px;
}

.autocomplete-field {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 16px 36px rgba(31, 41, 51, 0.16);
}

.autocomplete-option {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 9px 11px;
  background: #ffffff;
  color: var(--text);
  text-align: left;
}

.autocomplete-option:hover,
.autocomplete-option:focus {
  background: #e7f5f1;
  outline: none;
}

.autocomplete-option:last-child {
  border-bottom: 0;
}

.autocomplete-option span,
.autocomplete-empty {
  color: var(--muted);
  font-size: 12px;
}

.autocomplete-empty {
  padding: 12px;
}

.filters-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
  padding: 0 14px 14px;
}

.filters-bar label {
  margin-bottom: 0;
}

.filters-bar .secondary-button,
.filters-bar .primary-button {
  white-space: nowrap;
}

.encomenda-filters {
  grid-template-columns: 1fr;
}

.encomenda-filters .obra-filter {
  width: 100%;
}

.date-filter-row {
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(150px, 220px) auto;
  gap: 10px;
  align-items: end;
}

.logo-preview {
  display: flex;
  align-items: center;
  min-height: 70px;
  margin-top: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}

.logo-preview img {
  max-width: 220px;
  max-height: 72px;
  object-fit: contain;
}

.empty-row td {
  color: var(--muted);
  text-align: center;
  padding: 26px 14px;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #e9eef4;
}

.login-card {
  width: min(400px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(23, 33, 43, 0.18);
  padding: 24px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.login-brand strong,
.login-brand span {
  display: block;
}

.login-brand strong {
  font-size: 18px;
}

.login-brand span:not(.brand-mark) {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.login-error {
  margin: 0 0 14px;
  color: var(--danger);
  font-size: 13px;
}

.login-button {
  width: 100%;
  min-height: 42px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
  border-radius: 8px;
  background: #17212b;
  color: #ffffff;
  padding: 12px 14px;
  box-shadow: 0 16px 40px rgba(23, 33, 43, 0.22);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .sidebar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
  }

  .brand {
    padding: 0;
  }

  .main-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    margin-left: 0;
  }

  .nav-item {
    justify-content: center;
    text-align: center;
  }

  .workspace {
    padding: 18px;
  }

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

  .order-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: flex-start;
    flex-direction: column;
    width: 100%;
  }

  .current-user {
    justify-content: space-between;
    width: 100%;
  }

  .main-nav {
    display: grid;
    grid-template-columns: 1fr;
  }

  .subnav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .subnav-item {
    width: 100%;
  }

  .picker-row {
    grid-template-columns: 1fr;
  }

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

  .span-2 {
    grid-column: auto;
  }

  .compact-heading {
    display: grid;
  }

  .segmented {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .filters-bar {
    grid-template-columns: 1fr;
  }

  .date-filter-row {
    grid-template-columns: 1fr;
  }
}
