:root {
  color-scheme: dark;
  font-family: "Barlow", "Inter", Arial, sans-serif;
  --bg: #050806;
  --panel: #111714;
  --panel-strong: #17211c;
  --line: #26352d;
  --text: #f4fff8;
  --muted: #9cafaa;
  --green: #00ff57;
  --green-dark: #00b83e;
  --danger: #ff5964;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 30% 10%, rgba(0, 224, 96, 0.16), transparent 28%), var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.login-shell,
.portal-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: rgba(17, 23, 20, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.login-topline {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

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

h1 {
  font-size: 34px;
  line-height: 1;
  margin-bottom: 28px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 16px;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #070a08;
  color: var(--text);
  padding: 13px 14px;
  outline: none;
}

input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(0, 224, 96, 0.15);
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 46px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.password-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--green);
}

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

.primary-button,
.secondary-button,
.app-card {
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  border: 1px solid var(--green);
  background: linear-gradient(180deg, #74ff9a 0%, var(--green) 48%, var(--green-dark) 100%);
  box-shadow: 0 8px 18px rgba(0, 255, 87, 0.22), 0 3px 0 #001f0a;
  color: #001607;
  font-weight: 800;
  padding: 14px;
}

.primary-button:hover,
.logout-button:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.secondary-button {
  background: var(--panel-strong);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 14px;
}

.danger-button {
  background: rgba(255, 89, 100, 0.12);
  color: var(--danger, #ff5964);
  border: 1px solid rgba(255, 89, 100, 0.4);
  border-radius: 7px;
  padding: 10px 14px;
  cursor: pointer;
}

.danger-button:hover {
  background: rgba(255, 89, 100, 0.22);
}

.link-button {
  background: none;
  border: none;
  color: var(--text-muted, #888);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  width: 100%;
}

.link-button:hover {
  color: var(--text);
}

.error {
  color: var(--danger);
  background: rgba(255, 89, 100, 0.12);
  border: 1px solid rgba(255, 89, 100, 0.5);
  border-radius: 7px;
  padding: 12px;
}

.success {
  color: var(--green);
  background: rgba(0, 224, 96, 0.1);
  border: 1px solid rgba(0, 224, 96, 0.38);
  border-radius: 7px;
  padding: 12px;
}

.portal-shell {
  align-items: start;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 24px;
  place-items: unset;
}

.portal {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.side-rail {
  position: sticky;
  top: 24px;
  align-self: start;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  min-height: calc(100vh - 48px);
  border-right: 1px solid var(--line);
  padding: 18px 18px 18px 0;
}

.side-nav {
  display: grid;
  align-content: start;
  gap: 10px;
}

.side-nav button {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 10px 12px;
  text-align: left;
}

.side-nav button:hover,
.side-nav button.active {
  border-color: rgba(0, 224, 96, 0.28);
  background: rgba(0, 224, 96, 0.08);
}

.side-rail svg,
.logout-button svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--green);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.side-footer {
  display: grid;
  align-self: end;
  gap: 12px;
}

.side-user-card {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
}

.side-user-card strong,
.side-user-card small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-user-card small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.side-user-avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: var(--green);
}

.logout-button {
  width: 100%;
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border: 1px solid var(--green);
  border-radius: 7px;
  background: linear-gradient(180deg, #74ff9a 0%, var(--green) 48%, var(--green-dark) 100%);
  box-shadow: 0 8px 18px rgba(0, 255, 87, 0.22), 0 3px 0 #001f0a;
  color: #001607;
  cursor: pointer;
  font-weight: 800;
  padding: 10px 12px;
  text-align: left;
}

.logout-button svg {
  width: 20px;
  height: 20px;
  stroke: #001607;
}

.portal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding: 20px 0;
}

.portal-title-block {
  display: grid;
  align-items: start;
  gap: 12px;
}

.header-brand-logo {
  width: min(360px, 42vw);
  max-height: 58px;
  object-fit: contain;
  object-position: left center;
}

.portal-title-block h1 {
  margin-bottom: 0;
}

.header-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
}

.language-flags {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.language-flags button {
  width: 40px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(17, 23, 20, 0.72);
  cursor: pointer;
  opacity: 0.4;
  transition: border-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease, transform 160ms ease;
}

.language-flags button:hover {
  border-color: rgba(0, 255, 87, 0.78);
  box-shadow: 0 8px 18px rgba(0, 255, 87, 0.16);
  opacity: 0.78;
  transform: translateY(-1px);
}

.language-flags button.selected {
  border-color: var(--green);
  box-shadow: 0 8px 18px rgba(0, 255, 87, 0.18);
  opacity: 1;
}

.flag {
  position: relative;
  width: 28px;
  height: 18px;
  display: block;
  overflow: hidden;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.flag-es {
  background: linear-gradient(#c60b1e 0 25%, #ffc400 25% 75%, #c60b1e 75% 100%);
}

.flag-it {
  background: linear-gradient(90deg, #008c45 0 33.33%, #f4f5f0 33.33% 66.66%, #cd212a 66.66% 100%);
}

.flag-fr {
  background: linear-gradient(90deg, #0055a4 0 33.33%, #fff 33.33% 66.66%, #ef4135 66.66% 100%);
}

.flag-de {
  background: linear-gradient(#000 0 33.33%, #dd0000 33.33% 66.66%, #ffce00 66.66% 100%);
}

.flag-pt {
  background: linear-gradient(90deg, #006600 0 40%, #ff0000 40% 100%);
}

.flag-gb {
  background:
    linear-gradient(90deg, transparent 42%, #fff 42% 58%, transparent 58%),
    linear-gradient(0deg, transparent 38%, #fff 38% 62%, transparent 62%),
    linear-gradient(32deg, transparent 45%, #fff 45% 53%, transparent 53%),
    linear-gradient(-32deg, transparent 45%, #fff 45% 53%, transparent 53%),
    #012169;
}

.flag-gb::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(32deg, transparent 47%, #c8102e 47% 51%, transparent 51%),
    linear-gradient(-32deg, transparent 47%, #c8102e 47% 51%, transparent 51%);
}

.flag-gb::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 45%, #c8102e 45% 55%, transparent 55%),
    linear-gradient(0deg, transparent 42%, #c8102e 42% 58%, transparent 58%);
}

.avatar-menu {
  position: relative;
}

.avatar-button,
.avatar-editor {
  position: relative;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(0, 224, 96, 0.45);
  border-radius: 50%;
  background: var(--green);
  color: #020604;
  cursor: pointer;
}

.avatar-button {
  padding: 0;
}

.avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.default-avatar-mark {
  font-weight: 900;
  letter-spacing: 0;
  color: #020604;
}

.floating-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 20;
  width: 220px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c120f;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
}

.floating-menu button {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 13px 14px;
  text-align: left;
}

.floating-menu button:last-child {
  border-bottom: 0;
}

.floating-menu button:hover {
  background: rgba(0, 224, 96, 0.11);
}

.pending-badge {
  display: inline-block;
  background: rgba(255, 200, 60, 0.15);
  color: #f0b429;
  border: 1px solid rgba(255, 200, 60, 0.35);
  border-radius: 4px;
  font-size: 0.72rem;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

.user-meta {
  color: var(--muted);
  margin-bottom: 0;
}

.apps-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 16px;
  margin-top: 28px;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.page-panel {
  margin-top: 28px;
}

.country-search {
  width: min(340px, 100%);
  margin-bottom: 0;
}

.new-company-button {
  width: auto;
  min-width: 96px;
}

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

.company-card {
  min-height: 148px;
  display: grid;
  grid-template-columns: minmax(120px, 30%) minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 23, 20, 0.82);
}

.company-card-media {
  display: grid;
  place-items: center;
  min-height: 148px;
  background: rgba(0, 224, 96, 0.1);
  color: var(--green);
  font-size: 28px;
  font-weight: 900;
}

.company-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.company-card-body {
  min-width: 0;
  padding: 14px;
}

.fiscal-name {
  display: block;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 4px;
}

.company-card h2 {
  font-size: 20px;
  line-height: 1.05;
  margin-bottom: 10px;
}

.company-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.company-fields span {
  color: var(--muted);
}

.company-fields strong {
  display: block;
  color: var(--text);
  font-size: 12px;
  margin-bottom: 2px;
}

.icon-edit-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 224, 96, 0.34);
  border-radius: 7px;
  background: rgba(0, 224, 96, 0.08);
  color: var(--green);
  cursor: pointer;
}

.icon-edit-button:hover {
  background: rgba(0, 224, 96, 0.16);
  border-color: var(--green);
}

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

.card-edit-button,
.table-edit-button {
  width: auto;
  margin-top: 14px;
}

.table-edit-button {
  display: block;
  margin-top: 8px;
}

.modal-checks {
  margin-top: 16px;
}

.app-card {
  width: 144px;
  min-height: 158px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 10px;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.app-card:hover {
  border-color: rgba(0, 255, 87, 0.32);
  background: rgba(0, 255, 87, 0.07);
  box-shadow: 0 16px 36px rgba(0, 255, 87, 0.1);
  transform: translateY(-2px);
}

.app-card strong {
  display: block;
  font-family: "Barlow", "Inter", Arial, sans-serif;
  font-size: 19px;
  font-style: italic;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 0;
}

.app-icon-slot {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
}

.app-icon-slot img,
.app-icon-slot svg {
  width: 92px;
  height: 92px;
  object-fit: contain;
}

.app-icon-slot svg {
  fill: rgba(0, 224, 96, 0.13);
  stroke: var(--green);
  stroke-width: 2;
}

.app-icon-slot text {
  fill: var(--green);
  font-size: 24px;
  font-weight: 900;
}

.app-card > span:not(.app-icon-slot) {
  color: var(--muted);
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(0, 224, 96, 0.12);
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  margin-top: 18px;
}

.admin-panel {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.user-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  align-items: start;
  background: rgba(17, 23, 20, 0.75);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #070a08;
  color: var(--text);
  padding: 13px 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.62);
}

.preferences-card {
  width: min(620px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101713;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  padding: 24px;
}

.company-modal {
  width: min(960px, calc(100vw - 48px));
  max-height: none;
  overflow: visible;
  padding: 18px;
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.avatar-editor {
  width: 112px;
  height: 112px;
  margin: 10px auto 22px;
}

.avatar-editor input {
  display: none;
}

.company-image-editor {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 224, 96, 0.08);
  color: var(--green);
  cursor: pointer;
  margin: 10px 0 18px;
}

.company-image-editor input {
  display: none;
}

.company-image-editor img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 10px;
}

.company-image-editor > span:first-of-type svg {
  width: 42px;
  height: 42px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.company-image-editor:hover .avatar-edit-overlay {
  opacity: 1;
}

.company-modal-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) minmax(0, 1.8fr);
  gap: 16px;
  align-items: start;
}

.company-modal .company-image-editor {
  aspect-ratio: 1 / 1;
  margin: 0;
  background: #050806;
}

.company-modal .company-form-grid {
  gap: 10px 12px;
}

.company-modal label {
  gap: 6px;
  font-size: 13px;
  margin-bottom: 0;
}

.company-modal input,
.company-modal select {
  min-height: 42px;
  padding: 10px 12px;
}

.company-modal .error {
  margin: 12px 0 0;
}

.company-modal .modal-actions {
  grid-template-columns: 1fr auto auto;
  margin-top: 14px;
}

.avatar-edit-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 224, 96, 0.72);
  color: #001607;
  opacity: 0;
  transition: opacity 160ms ease;
}

.avatar-editor:hover .avatar-edit-overlay {
  opacity: 1;
}

.avatar-edit-overlay svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

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

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

input:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.phone-row {
  display: grid;
  grid-template-columns: minmax(118px, 0.42fr) minmax(160px, 1fr);
  gap: 10px;
}

.modal-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 20px;
}

.modal-actions .primary-button,
.modal-actions .secondary-button,
.user-form .primary-button {
  width: auto;
}

.app-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  grid-column: 1 / -1;
}

.app-checks label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.app-checks input {
  width: auto;
}

.users-table {
  overflow-x: auto;
  margin-top: 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(17, 23, 20, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

th {
  color: var(--muted);
  font-size: 13px;
}

td span {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

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

  .side-rail {
    position: static;
    min-height: auto;
    grid-template-rows: auto auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 16px;
  }

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

  .side-footer {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .logout-button {
    width: auto;
  }

  .header-brand-logo {
    width: min(320px, 100%);
    max-height: 52px;
  }

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

  .header-actions {
    justify-content: space-between;
  }

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

  .form-grid,
  .company-card,
  .company-modal-layout,
  .company-fields,
  .phone-row,
  .modal-actions {
    grid-template-columns: 1fr;
  }

  .company-modal {
    width: min(560px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    overflow: auto;
  }

  .company-modal .company-image-editor {
    aspect-ratio: 3 / 1;
  }

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

  .company-card-media {
    min-height: 150px;
  }

  .modal-actions .primary-button,
  .modal-actions .secondary-button {
    width: 100%;
  }
}
