:root {
  --portal-ink: #18212d;
  --portal-muted: #6b7280;
  --portal-border: #d7dee6;
  --portal-surface: #ffffff;
  --portal-surface-soft: #f5f7fb;
  --portal-brand: #0f5b8d;
  --portal-brand-strong: #083f63;
  --portal-success: #157f57;
  --portal-warning: #b26717;
}

html {
  font-size: 16px;
}

body.portal-body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f3f7fb 0%, #f8fafc 100%);
  color: var(--portal-ink);
}

.portal-header {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--portal-border);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.portal-main {
  padding: 2rem 0 3rem;
}

.portal-footer {
  padding: 1rem 0 2rem;
  color: var(--portal-muted);
  font-size: 0.9rem;
}

.portal-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.9rem;
  text-decoration: none;
  color: var(--portal-ink);
}

.portal-brand-mark {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--portal-brand) 0%, var(--portal-brand-strong) 100%);
  color: white;
  font-weight: 700;
}

.portal-brand-title {
  display: block;
  font-size: 1rem;
  font-weight: 700;
}

.portal-brand-subtitle {
  display: block;
  font-size: 0.78rem;
  color: var(--portal-muted);
}

.portal-user-chip {
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  background: var(--portal-surface-soft);
  border: 1px solid var(--portal-border);
  line-height: 1.15;
}

.portal-user-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.portal-user-meta {
  font-size: 0.72rem;
  color: var(--portal-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.portal-link {
  color: var(--portal-brand-strong);
  text-decoration: none;
  font-weight: 600;
}

.portal-btn-primary,
.portal-btn-secondary {
  border-radius: 0.8rem;
  padding: 0.65rem 1rem;
  font-weight: 600;
}

.portal-btn-primary {
  background: linear-gradient(135deg, var(--portal-brand) 0%, var(--portal-brand-strong) 100%);
  color: white;
  border: 0;
}

.portal-btn-primary:hover {
  color: white;
  opacity: 0.95;
}

.portal-btn-secondary {
  background: white;
  color: var(--portal-ink);
  border: 1px solid var(--portal-border);
}

.portal-grid {
  display: grid;
  gap: 1.25rem;
}

.portal-grid.two {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
}

.portal-card {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: 1.4rem;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
}

.portal-card-header {
  padding: 1.2rem 1.4rem 0.6rem;
}

.portal-card-body {
  padding: 0.75rem 1.4rem 1.3rem;
}

.portal-card-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.portal-card-subtitle {
  margin-top: 0.35rem;
  color: var(--portal-muted);
  font-size: 0.92rem;
}

.portal-stat-list,
.portal-message-list,
.portal-attachment-list,
.portal-procedure-list,
.portal-project-list {
  display: grid;
  gap: 0.85rem;
}

.portal-stat {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 1rem;
  background: var(--portal-surface-soft);
  border: 1px solid #e5eaf1;
}

.portal-stat-label {
  color: var(--portal-muted);
  font-size: 0.88rem;
}

.portal-stat-value {
  font-weight: 700;
}

.portal-message,
.portal-attachment,
.portal-procedure {
  padding: 1rem;
  border-radius: 1rem;
  border: 1px solid var(--portal-border);
  background: white;
}

.portal-message.system {
  background: #f6f8fb;
}

.portal-meta {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  color: var(--portal-muted);
  font-size: 0.83rem;
  margin-bottom: 0.5rem;
}

.portal-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: #edf4fa;
  color: var(--portal-brand-strong);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.portal-pill.success {
  background: #e8f8f1;
  color: var(--portal-success);
}

.portal-pill.warning {
  background: #fff4e8;
  color: var(--portal-warning);
}

.portal-login-shell {
  min-height: calc(100vh - 8rem);
  display: grid;
  place-items: center;
}

.portal-login-card {
  width: min(100%, 28rem);
}

.portal-table {
  width: 100%;
  border-collapse: collapse;
}

.portal-table th,
.portal-table td {
  padding: 0.8rem 0.7rem;
  border-bottom: 1px solid var(--portal-border);
  vertical-align: top;
}

.portal-table th {
  color: var(--portal-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.portal-table tr:last-child td {
  border-bottom: 0;
}

.portal-form-stack {
  display: grid;
  gap: 0.75rem;
}

.portal-empty {
  padding: 1rem;
  border-radius: 1rem;
  background: var(--portal-surface-soft);
  color: var(--portal-muted);
}

.portal-project-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.portal-chat-shell {
  display: grid;
  gap: 1rem;
}

.portal-chat-thread {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  border-radius: 1.2rem;
  background:
    linear-gradient(180deg, rgba(15, 91, 141, 0.04) 0%, rgba(255, 255, 255, 0.96) 100%),
    var(--portal-surface-soft);
  border: 1px solid #dce4ee;
}

.portal-chat-row {
  display: flex;
}

.portal-chat-row.outgoing {
  justify-content: flex-end;
}

.portal-chat-row.system {
  justify-content: center;
}

.portal-chat-bubble {
  width: min(100%, 44rem);
  padding: 1rem 1.1rem;
  border-radius: 1.2rem;
  border: 1px solid var(--portal-border);
  background: white;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.05);
}

.portal-chat-row.outgoing .portal-chat-bubble {
  background: linear-gradient(135deg, #edf4ff 0%, #dfeeff 100%);
  border-color: #b7cdf3;
}

.portal-chat-row.internal .portal-chat-bubble {
  background: linear-gradient(135deg, #eff7ff 0%, #f8fbff 100%);
  border-color: #c7d9ee;
}

.portal-chat-row.client .portal-chat-bubble {
  background: linear-gradient(135deg, #fff4e6 0%, #fffaf2 100%);
  border-color: #f0cf9f;
}

.portal-chat-row.contractor .portal-chat-bubble {
  background: linear-gradient(135deg, #edf8f2 0%, #f7fcf9 100%);
  border-color: #b9dcc7;
}

.portal-chat-row.system .portal-chat-bubble {
  width: min(100%, 34rem);
  background: #f6f8fb;
  border-color: #d7dee6;
}

.portal-chat-topline {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.portal-chat-role {
  display: inline-flex;
  align-items: center;
  min-height: 1.8rem;
  padding: 0.15rem 0.7rem;
  border-radius: 999px;
  background: rgba(24, 33, 45, 0.08);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.portal-chat-row.outgoing .portal-chat-role {
  background: var(--portal-brand);
  color: white;
}

.portal-chat-row.contractor .portal-chat-role {
  background: var(--portal-success);
  color: white;
}

.portal-chat-row.client .portal-chat-role {
  background: var(--portal-warning);
  color: white;
}

.portal-chat-row.external .portal-chat-bubble {
  background: linear-gradient(135deg, #fff4e6 0%, #fffaf2 100%);
  border-color: #f0cf9f;
}

.portal-chat-row.external .portal-chat-role {
  background: var(--portal-warning);
  color: white;
}

.portal-chat-time {
  font-size: 0.78rem;
  color: var(--portal-muted);
}

.portal-chat-author {
  margin-top: 0.7rem;
  font-size: 0.92rem;
  font-weight: 700;
}

.portal-chat-content {
  margin-top: 0.65rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.portal-chat-composer {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 1.1rem;
  background: white;
  border: 1px solid var(--portal-border);
}

.portal-chat-textarea {
  min-height: 7rem;
  resize: vertical;
}

.portal-chat-hint {
  color: var(--portal-muted);
  font-size: 0.85rem;
}

.portal-tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.portal-tab-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.9rem;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--portal-border);
  color: var(--portal-ink);
  text-decoration: none;
  font-weight: 700;
}

.portal-tab-link.active {
  background: linear-gradient(135deg, var(--portal-brand) 0%, var(--portal-brand-strong) 100%);
  border-color: transparent;
  color: white;
  box-shadow: 0 10px 24px rgba(8, 63, 99, 0.22);
}

.portal-overview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
}

.portal-overview-tile {
  padding: 1rem 1.1rem;
  border-radius: 1.1rem;
  border: 1px solid var(--portal-border);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.portal-overview-tile.compact {
  min-width: 10rem;
}

.portal-overview-label {
  color: var(--portal-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.portal-overview-value {
  margin-top: 0.45rem;
  font-size: 1.5rem;
  font-weight: 800;
}

.portal-user-mini {
  font-size: 0.82rem;
  color: var(--portal-muted);
  font-weight: 700;
}

.portal-list {
  display: grid;
  gap: 0.85rem;
}

.portal-list-item {
  padding: 1rem;
  border-radius: 1rem;
  border: 1px solid var(--portal-border);
  background: white;
}

.portal-note {
  padding: 1rem 1.1rem;
  border-radius: 1rem;
  border: 1px solid var(--portal-border);
  background: var(--portal-surface-soft);
  white-space: pre-wrap;
  line-height: 1.55;
}

.portal-section-title {
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--portal-muted);
  font-weight: 800;
}

.portal-finance-total,
.portal-finance-inline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.95rem 1rem;
  border-radius: 1rem;
  background: linear-gradient(180deg, #f7fbff 0%, #eef6ff 100%);
  border: 1px solid #d2e3f6;
}

.portal-finance-total strong,
.portal-finance-inline {
  font-size: 1.1rem;
  font-weight: 800;
}

.portal-project-card {
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.portal-project-link:hover .portal-project-card {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(16, 24, 40, 0.1);
  border-color: #c8d5e3;
}

@media (max-width: 992px) {
  .portal-grid.two {
    grid-template-columns: 1fr;
  }

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

  .portal-chat-bubble {
    width: 100%;
  }
}
