:root {
  color-scheme: light;
  --bg: #F5F8FC;
  --panel: #ffffff;
  --line: #D7DEE8;
  --text: #17233C;
  --muted: #667085;
  --accent: #0057C8;
  --accent-strong: #0049A8;
  --shadow: 0 18px 46px rgba(23, 35, 60, 0.12);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body:not(.authenticated) {
  display: block;
  background: #EAF0F7;
}

body:not(.authenticated) aside {
  display: none;
}

body:not(.authenticated) main {
  padding: 0;
}

aside {
  background: #18212f;
  color: #fff;
  padding: 24px 18px;
}

h1 {
  margin: 0 0 24px;
  font-size: 22px;
}

nav {
  display: grid;
  gap: 8px;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

nav button {
  border-color: transparent;
  background: transparent;
  color: #dbe4ef;
  text-align: left;
  padding: 10px 12px;
}

nav button.active,
nav button:hover {
  background: #263244;
  color: #fff;
}

main {
  padding: 24px;
}

section,
header,
form,
#tenant-bar,
.table-wrap {
  max-width: 1180px;
}

#login-panel {
  min-height: 100vh;
  max-width: none;
  position: relative;
  overflow: hidden;
}

#login-form {
  position: relative;
  z-index: 2;
  grid-column: 2;
  align-self: center;
  justify-self: center;
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 44px;
  margin: 0;
}

.login-shell {
  min-height: 100vh;
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(420px, 0.72fr);
  grid-template-rows: 104px minmax(560px, 1fr) 72px;
  column-gap: 48px;
  padding: 0 clamp(28px, 4vw, 56px);
  background:
    linear-gradient(90deg, rgba(255,255,255,0.88), rgba(245,248,252,0.92)),
    #F5F8FC;
  border-left: 1px solid #DFE6F0;
  border-right: 1px solid #DFE6F0;
  box-shadow: 0 0 44px rgba(23, 35, 60, 0.05);
}

.login-brand {
  grid-column: 1 / -1;
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 28px;
  max-width: none;
  margin: 0 calc(clamp(28px, 4vw, 56px) * -1);
  padding: 0 clamp(28px, 4vw, 56px);
  background: linear-gradient(180deg, #FFFFFF 0%, #F3F7FC 100%);
  border-bottom: 1px solid var(--line);
}

.login-logo {
  width: 162px;
  height: 90px;
  object-fit: contain;
  object-position: center;
  display: block;
}

.brand-divider {
  width: 1px;
  height: 48px;
  background: var(--line);
}

.brand-title {
  display: grid;
  gap: 8px;
  max-width: 520px;
}

.brand-title strong {
  color: #34425F;
  font-size: 26px;
  line-height: 1.2;
}

.brand-title span {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.35;
}

.login-visual {
  grid-column: 1;
  grid-row: 2;
  position: relative;
  min-height: 540px;
  align-self: stretch;
  overflow: hidden;
  margin-left: calc(clamp(28px, 4vw, 56px) * -1);
  background:
    linear-gradient(90deg, rgba(245, 248, 252, 0) 0%, rgba(245, 248, 252, 0.08) 62%, #F5F8FC 100%),
    url("/assets/login-bg-rial-base.png") left center / cover no-repeat;
}

.login-visual::before {
  content: "";
  position: absolute;
  inset: 13% -8% 4% -2%;
  background:
    linear-gradient(90deg, rgba(0, 87, 200, 0.10) 1px, transparent 1px),
    linear-gradient(0deg, rgba(0, 87, 200, 0.08) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(120deg, #000 0%, rgba(0,0,0,0.62) 48%, transparent 88%);
  opacity: 0;
}

.login-visual::after {
  content: "";
  position: absolute;
  inset: 12% 12% 10% 0;
  background:
    radial-gradient(circle at 20% 50%, rgba(0, 87, 200, 0.32) 0 3px, transparent 4px),
    radial-gradient(circle at 45% 36%, rgba(0, 87, 200, 0.22) 0 3px, transparent 4px),
    radial-gradient(circle at 58% 62%, rgba(0, 87, 200, 0.18) 0 3px, transparent 4px),
    linear-gradient(115deg, transparent 12%, rgba(0, 87, 200, 0.16) 12.2%, transparent 12.8% 34%, rgba(0, 87, 200, 0.12) 34.2%, transparent 34.8%),
    linear-gradient(25deg, transparent 18%, rgba(0, 87, 200, 0.14) 18.2%, transparent 18.8% 52%, rgba(0, 87, 200, 0.10) 52.2%, transparent 52.8%);
  opacity: 0;
}

.tech-chip {
  position: absolute;
  left: 18%;
  top: 33%;
  width: 280px;
  height: 198px;
  transform: rotateX(58deg) rotateZ(-38deg);
  transform-style: preserve-3d;
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(255,255,255,0.94), rgba(213, 225, 244, 0.56));
  box-shadow: 0 28px 70px rgba(0, 87, 200, 0.13);
  opacity: 0;
}

.tech-chip::before,
.tech-chip::after {
  content: "";
  position: absolute;
  inset: 28px;
  border: 1px solid rgba(0, 87, 200, 0.18);
  border-radius: 18px;
  background: rgba(255,255,255,0.42);
}

.tech-chip::after {
  inset: 72px 98px 48px;
  background: linear-gradient(180deg, rgba(0, 87, 200, 0.38), rgba(255,255,255,0.45));
  box-shadow: 0 18px 40px rgba(0, 87, 200, 0.22);
}

.tech-chip span {
  position: absolute;
  width: 52px;
  height: 52px;
  border: 1px solid rgba(0, 87, 200, 0.18);
  background: rgba(255,255,255,0.52);
  transform: rotateZ(30deg);
}

.tech-chip span:nth-child(1) { left: -92px; top: 48px; }
.tech-chip span:nth-child(2) { right: -74px; top: -20px; }
.tech-chip span:nth-child(3) { right: 16px; bottom: -82px; }

.tech-grid {
  position: absolute;
  left: 0;
  right: 8%;
  bottom: 0;
  height: 190px;
  background:
    linear-gradient(90deg, transparent 0 22%, rgba(0, 87, 200, 0.18) 22.4%, transparent 22.8% 46%, rgba(0, 87, 200, 0.12) 46.4%, transparent 46.8%),
    linear-gradient(0deg, transparent 0 34%, rgba(0, 87, 200, 0.14) 34.4%, transparent 34.8% 66%, rgba(0, 87, 200, 0.10) 66.4%, transparent 66.8%);
  opacity: 0;
}

#login-form h2 {
  margin-bottom: 12px;
  font-size: 28px;
  color: #0F1F3D;
}

.login-subtitle {
  margin-bottom: 30px;
  color: #55647C;
  font-size: 16px;
}

#login-form label {
  color: #20304D;
  font-size: 15px;
  font-weight: 700;
}

#login-form input {
  min-height: 54px;
  border-radius: 6px;
  font-size: 16px;
  background: #fff;
}

#login-form input::placeholder {
  color: #8A96AA;
}

#login-form input:invalid {
  border-color: var(--line);
}

.login-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.check-label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: #34425F;
  font-weight: 400;
}

.check-label input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.login-link,
.login-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.login-link:hover,
.login-footer a:hover {
  text-decoration: underline;
}

.login-separator {
  display: flex;
  align-items: center;
  gap: 16px;
  color: #8A96AA;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.login-separator::before,
.login-separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #E4EAF2;
}

.secondary-action {
  min-height: 54px;
  border-color: var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-weight: 700;
  font-size: 17px;
}

.secondary-action:hover {
  background: #EFF6FF;
}

.login-footer {
  grid-column: 1 / -1;
  min-height: 72px;
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 1fr 0.5fr;
  align-items: center;
  gap: 20px;
  margin: 0 calc(clamp(28px, 4vw, 56px) * -1);
  padding: 0 clamp(28px, 4vw, 56px);
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #F6F9FD 0%, #ECF2F8 100%);
  color: #52627A;
  font-size: 15px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h2 {
  margin: 0 0 4px;
  font-size: 24px;
}

p {
  margin: 0;
  color: var(--muted);
}

form {
  display: grid;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px;
  margin-bottom: 16px;
}

#tenant-bar {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px 16px;
  margin-bottom: 16px;
}

#tenant-bar label {
  max-width: 420px;
}

#create-form {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--text);
}

button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

button[type="submit"]:hover {
  background: var(--accent-strong);
}

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
}

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

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

th {
  color: var(--muted);
  background: #f9fafb;
  font-size: 12px;
  text-transform: uppercase;
}

#login-error {
  color: #b91c1c;
  min-height: 18px;
}

#form-message {
  min-height: 20px;
  margin: -6px 0 16px;
  font-size: 14px;
}

.summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  max-width: 1180px;
  margin-bottom: 16px;
}

.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px;
}

.summary-card h3,
.summary-card h4 {
  margin: 0 0 8px;
}

.summary-card h3 {
  font-size: 17px;
}

.summary-card h4 {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.summary-card ul {
  margin: 0;
  padding-left: 18px;
}

.summary-card li {
  margin-bottom: 4px;
}

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

.error {
  color: #b91c1c;
}

.success {
  color: #047857;
}

input:invalid,
select:invalid,
textarea:invalid {
  border-color: #dc2626;
}

@media (max-width: 1100px) {
  .login-shell {
    width: min(980px, calc(100% - 32px));
    grid-template-columns: minmax(300px, 0.8fr) minmax(380px, 1fr);
    column-gap: 28px;
  }

  .brand-title strong {
    font-size: 22px;
  }

  .brand-title span {
    font-size: 15px;
  }

  #login-form {
    padding: 34px;
  }
}

@media (max-width: 820px) {
  body {
    grid-template-columns: 1fr;
  }

  aside {
    position: static;
  }

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

  .login-shell {
    width: 100%;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
    padding: 0 18px;
    border-left: 0;
    border-right: 0;
  }

  .login-brand {
    margin: 0 -18px;
    padding: 18px;
    gap: 16px;
  }

  .login-logo {
    width: 138px;
    height: 78px;
  }

  .brand-divider {
    height: 42px;
  }

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

  .brand-title span {
    font-size: 13px;
  }

  .login-visual {
    min-height: 160px;
    grid-row: 2;
    margin-left: 0;
    background-position: left 44%;
  }

  .tech-chip {
    left: 8%;
    top: 6%;
    width: 170px;
    height: 120px;
  }

  #login-form {
    grid-column: 1;
    padding: 26px 20px;
    align-self: start;
  }

  .login-footer {
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 0 -18px;
    padding: 16px 18px;
    font-size: 14px;
  }
}
