*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #1565c0;
  --blue-dark: #0d47a1;
  --blue-light: #e3f2fd;
  --blue-mid: #e8f0fe;
  --green: #2e7d32;
  --green-light: #e8f5e9;
  --red: #c62828;
  --red-light: #fce4ec;
  --amber: #e65100;
  --text: #212121;
  --text-secondary: #757575;
  --text-hint: #9e9e9e;
  --border: #e0e0e0;
  --surface: #ffffff;
  --bg: #f5f5f5;
  --sidebar-width: 280px;
  --topbar-height: 56px;
}

body {
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  background: var(--blue);
  color: #fff;
  height: var(--topbar-height);
  padding: 0 24px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar h1 { font-size: 20px; font-weight: 500; letter-spacing: .5px; }

/* Two-column layout */
.layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--topbar-height));
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
}

/* Main area */
.main {
  flex: 1;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: none;
}

/* Sidebar shared */
.sidebar-section {
  padding: 20px;
  border-bottom: 1px solid #f0f0f0;
}
.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-hint);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 14px;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-nav-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 9px 10px;
  border-radius: 4px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background .2s, color .2s;
}
.sidebar-nav-item:hover {
  background: var(--blue-light);
  color: var(--blue-dark);
}
.sidebar-nav-item.active {
  background: var(--blue-mid);
  color: var(--blue-dark);
}

/* Form fields */
.field-group { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.field-wrap { display: flex; flex-direction: column; gap: 4px; }
.field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-hint);
  letter-spacing: .5px;
  text-transform: uppercase;
}
.field-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  background: #fafafa;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(21,101,192,.1);
  background: var(--surface);
}

/* Buttons */
.btn {
  width: 100%;
  padding: 9px 0;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: .3px;
  transition: background .2s;
  font-family: inherit;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: #f1f3f4; color: var(--text); }
.btn-secondary:hover { background: #e8eaed; }
.btn:focus { box-shadow: 0 0 0 2px rgba(21,101,192,.1); outline: none; }

/* Sync status */
.sync-row { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
.sync-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #4caf50;
  flex-shrink: 0;
  margin-top: 4px;
}
.sync-text { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }
.sync-text strong { display: block; color: #424242; font-size: 13px; }

/* Accordion */
.accordion {
  background: var(--surface);
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  overflow: hidden;
}
.accordion-header {
  background: transparent;
  border: 0;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  user-select: none;
  border-left: 3px solid transparent;
  transition: background .15s;
  text-align: left;
  width: 100%;
}
.accordion-header.open {
  border-left-color: var(--blue);
  background: #fafcff;
}
.accordion-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.accordion-badge {
  background: var(--blue-light);
  color: var(--blue);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.accordion-chevron {
  color: var(--text-hint);
  font-size: 18px;
  line-height: 1;
  transition: transform .2s;
  display: inline-block;
}
.accordion-chevron.open { transform: rotate(180deg); }
.accordion-body {
  border-top: 1px solid #f0f0f0;
  display: none;
}
.accordion-body.open { display: block; }

/* Licitação cards */
.lic-card-form {
  display: block;
}

.list-page {
  width: 100%;
}
.list-page-body {
  width: 100%;
}
.list-filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
  margin-bottom: 16px;
  padding: 16px;
}
.list-filter-header {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 14px;
}
.list-filter-header h2 {
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}
.list-filter-grid {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.advanced-filter-grid {
  align-items: start;
  gap: 12px 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  padding: 0;
}
.advanced-filter-grid .field-wrap {
  gap: 6px;
  min-width: 0;
}
.advanced-filter-grid .field-label {
  align-items: flex-end;
  display: flex;
  min-height: 28px;
  overflow-wrap: anywhere;
}
.list-filter-search {
  min-width: 0;
}
.list-filter-submit {
  flex: 0 0 auto;
  padding-left: 18px;
  padding-right: 18px;
  width: auto;
}
.list-filter-submit.is-loading {
  cursor: wait;
  opacity: .78;
}
.form-loading-state {
  align-items: center;
  color: var(--text-secondary);
  display: flex;
  font-size: 12px;
  font-weight: 600;
  gap: 8px;
  margin-top: 12px;
}
.form-loading-state[hidden] {
  display: none;
}
.form-loading-state::before {
  animation: spin .7s linear infinite;
  border: 2px solid var(--blue-light);
  border-top-color: var(--blue);
  border-radius: 50%;
  content: "";
  height: 14px;
  width: 14px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.filter-picker-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) 96px;
}
.filter-picker-row .field-input {
  min-width: 0;
}
.filter-picker-row .btn {
  height: 40px;
  padding-left: 8px;
  padding-right: 8px;
  width: auto;
}
.filter-picker-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}
.filter-chip {
  background: var(--blue-light);
  border: 1px solid rgba(21,101,192,.18);
  border-radius: 999px;
  color: var(--blue-dark);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  max-width: 100%;
  overflow-wrap: anywhere;
  padding: 5px 9px;
  text-align: left;
}
.filter-accordion {
  margin-bottom: 16px;
}
.filter-accordion .accordion-body.open {
  padding: 14px 20px 16px;
}
.filter-accordion .field-input {
  height: 40px;
  width: 100%;
}
.bid-notice-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  list-style: none;
  width: 100%;
}
.bid-notice-list-item {
  width: 100%;
}
.list-toolbar {
  align-items: center;
  color: var(--text-secondary);
  display: flex;
  font-size: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}
.list-toolbar strong {
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}
.list-toolbar-kicker {
  color: var(--text-hint);
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  margin-bottom: 3px;
  text-transform: uppercase;
}
.lic-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  color: inherit;
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(320px, 1.25fr) minmax(460px, 1fr) auto;
  gap: 16px 24px;
  align-items: center;
  font-family: inherit;
  min-height: 164px;
  padding: 18px 20px;
  text-align: left;
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .15s;
  width: 100%;
}
.lic-card:hover {
  border-color: rgba(21,101,192,.28);
  box-shadow: 0 8px 20px rgba(33,33,33,.08);
  transform: translateY(-1px);
}
.lic-card:focus {
  box-shadow: 0 0 0 3px rgba(21,101,192,.16), 0 8px 20px rgba(33,33,33,.08);
  outline: none;
}
.lic-card.selected {
  background: var(--blue-mid);
  border-left: 3px solid var(--blue);
  padding-left: 17px;
}
.lic-card-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.lic-card-id {
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.lic-card-eyebrow {
  color: var(--text-hint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  line-height: 1.2;
  text-transform: uppercase;
}
.lic-description {
  color: var(--text);
  display: -webkit-box;
  font-size: 14px;
  line-height: 1.4;
  min-height: 78px;
  max-height: 78px;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}
.lic-agency {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.lic-card-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 16px;
  min-width: 0;
}
.lic-card-action {
  align-items: center;
  background: var(--blue-light);
  border-radius: 999px;
  color: var(--blue);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  justify-content: center;
  min-width: 88px;
  padding: 8px 12px;
  white-space: nowrap;
}
.lic-field { display: flex; flex-direction: column; gap: 2px; }
.lic-field.full { grid-column: 1 / -1; }
.lic-field-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.lic-field-value {
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.lic-field-value.bold { font-weight: 600; color: var(--blue); }

/* Status chips */
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.chip-green { background: var(--green-light); color: var(--green); }
.chip-blue  { background: var(--blue-light);  color: var(--blue); }
.chip-red   { background: var(--red-light);   color: var(--red); }

.pagination {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}
.pagination-pages {
  display: flex;
  gap: 6px;
}
.pagination-link,
.pagination-page {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--blue);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  height: 34px;
  justify-content: center;
  min-width: 34px;
  padding: 0 11px;
  text-decoration: none;
}
.pagination-link:hover,
.pagination-page:hover {
  border-color: rgba(21,101,192,.35);
  color: var(--blue-dark);
}
.pagination-link:focus,
.pagination-page:focus {
  box-shadow: 0 0 0 2px rgba(21,101,192,.14);
  outline: none;
}
.pagination-page.current {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.pagination-link.disabled {
  color: var(--text-hint);
  cursor: default;
}

/* Detail view */
.detail-layout {
  justify-content: center;
}
.detail-main {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px;
}
.detail-grid {
  padding: 20px;
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 16px 32px;
}
.detail-grid.visible { display: grid; }
.detail-field { display: flex; flex-direction: column; gap: 3px; }
.detail-field.full { grid-column: 1 / -1; }
.detail-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.detail-value { font-size: 14px; color: var(--text); }
.detail-value.highlight { color: var(--blue); font-weight: 600; }

.detail-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.back-link {
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.back-link:hover { color: var(--blue-dark); text-decoration: underline; }
.back-link:focus {
  border-radius: 4px;
  box-shadow: 0 0 0 2px rgba(21,101,192,.14);
  outline: none;
}

.file-list {
  display: grid;
  gap: 10px;
  padding: 16px 20px 20px;
}
.file-item {
  align-items: center;
  background: #f8f9fa;
  border: 1px solid #eeeeee;
  border-radius: 6px;
  color: var(--text);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 64px;
  padding: 12px 14px;
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.file-item:hover {
  border-color: rgba(21,101,192,.28);
  box-shadow: 0 6px 16px rgba(0,0,0,.06);
  transform: translateY(-1px);
}
.file-item:focus {
  box-shadow: 0 0 0 2px rgba(21,101,192,.14);
  outline: none;
}
.file-item-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.file-item-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.file-item-meta {
  color: var(--text-hint);
  font-size: 12px;
}
.file-item-action {
  color: var(--blue);
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

/* Empty state */
.empty-state,
.loading-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-hint);
  font-size: 13px;
}
.error-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--red);
  font-size: 13px;
}

/* 3x3 data grid */
.data-grid {
  padding: 20px;
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.data-grid.visible { display: grid; }
.data-cell {
  background: #f8f9fa;
  border: 1px solid #eeeeee;
  border-radius: 6px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.data-cell-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.data-cell-value { font-size: 15px; font-weight: 600; color: var(--text); }
.data-cell-value.blue  { color: var(--blue); }
.data-cell-value.green { color: var(--green); }
.data-cell-value.amber { color: var(--amber); }

/* AI Prompt */
.ai-section { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}
.ai-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
  outline: none;
  line-height: 1.5;
  transition: border-color .2s, box-shadow .2s;
}
.ai-textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(21,101,192,.1);
}
.ai-footer { display: flex; justify-content: flex-end; }
.btn-submit {
  padding: 9px 24px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background .2s;
}
.btn-submit:hover { background: var(--blue-dark); }

.page-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
  padding: 18px;
  width: 100%;
}
.page-panel-header {
  margin-bottom: 16px;
}
.page-panel-header h2 {
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}
.chat-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-thread {
  background: #f8f9fa;
  border: 1px solid #eeeeee;
  border-radius: 6px;
  min-height: 220px;
  padding: 14px;
}
.chat-message {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  max-width: 640px;
  padding: 12px;
}
.chat-message strong {
  color: var(--text);
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}
.chat-message p {
  font-size: 13px;
  line-height: 1.5;
}
.chat-form {
  align-items: flex-end;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    position: static;
  }

  .main {
    max-width: none;
    padding: 16px;
  }

  .detail-main {
    max-width: none;
    padding: 16px;
  }

  .lic-card {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .lic-card-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pagination {
    flex-wrap: wrap;
  }

  .list-filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-grid,
  .data-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .lic-card-meta {
    grid-template-columns: 1fr;
  }

  .lic-card-action {
    width: 100%;
  }

  .list-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .list-filter-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .list-filter-submit {
    width: 100%;
  }

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

  .chat-form .btn-submit {
    width: 100%;
  }
}

.list-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.list-pagination-status {
  font-size: 0.875rem;
  color: #64748b;
}

.list-pagination [aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

/* Workflow board */
.workflow-page { padding: 24px; }
.wf-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 16px;
  align-items: start;
  overflow-x: auto;
}
.wf-column {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-height: 200px;
}
.wf-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.wf-column-title { font-weight: 600; font-size: 14px; color: var(--text); }
.wf-column-count {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.wf-card-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.wf-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.wf-card-link { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; }
.wf-card-id { font-size: 11px; color: var(--text-secondary); }
.wf-card-object {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.wf-card-agency { font-size: 12px; color: var(--text-secondary); }
.wf-card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wf-card-value { font-size: 12px; font-weight: 600; color: var(--text); }
.wf-card-actions { display: flex; gap: 6px; border-top: 1px solid var(--border); padding-top: 8px; }
.wf-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 4px;
  padding: 4px 0;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}
.wf-btn:hover { background: var(--blue-light); color: var(--blue-dark); border-color: var(--blue); }
.wf-btn[hidden] { display: none; }
.wf-btn-remove:hover { background: var(--red-light); color: var(--red); border-color: var(--red); }

.lic-card-footer { display: flex; justify-content: flex-end; margin-top: 8px; }
.wf-add-btn.is-added {
  background: var(--green-light);
  color: var(--green);
  border-color: var(--green);
  cursor: default;
}
