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

:root {
  --red:       #E0201F;
  --red-dark:  #be1a19;
  --blue:      #1A3C8A;
  --blue-mid:  #1e47a6;
  --blue-light:#e8eef8;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
               'Microsoft YaHei', sans-serif;
  background: #f4f6fb;
  color: #111827;
  font-size: 14px;
}

/* ── Screens ─────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
}

/* ══════════════════════════════════════════════
   LOGIN
══════════════════════════════════════════════ */
.login-bg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--blue) 0%, #0f2557 40%, var(--red) 100%);
  padding: 24px;
  min-height: 100vh;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 44px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22);
}

.login-brand {
  text-align: center;
  margin-bottom: 36px;
}

.login-logo {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border-radius: 14px;
  margin: 0 auto 14px;
  display: block;
}

.login-brand-name {
  font-size: 22px;
  font-weight: 800;
  color: var(--blue);
  letter-spacing: 0.04em;
}

.login-brand-sub {
  font-size: 13px;
  color: #9ca3af;
  margin-top: 4px;
  letter-spacing: 0.05em;
}

/* ── Form fields ─────────────────────────────── */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: #111827;
  outline: none;
  background: #fafafa;
  transition: border-color 0.2s, background 0.2s;
}

.field input:focus {
  border-color: var(--blue);
  background: #fff;
}

.input-wrap {
  position: relative;
}

.input-wrap input {
  width: 100%;
  padding-right: 42px;
}

.eye-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: #9ca3af;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.eye-btn:hover { color: var(--blue); }

.eye-icon { width: 18px; height: 18px; }

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.remember-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: #6b7280;
  cursor: pointer;
  user-select: none;
}

.remember-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--blue);
  cursor: pointer;
}

/* ── Buttons ─────────────────────────────────── */
.btn-primary {
  background: var(--red);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover:not(:disabled) { background: var(--red-dark); }
.btn-primary:active:not(:disabled) { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-block { width: 100%; }

.btn-ghost {
  background: none;
  border: 1.5px solid #e5e7eb;
  color: #374151;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  border-radius: 8px;
  padding: 8px 20px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.btn-ghost:hover { border-color: #9ca3af; }

/* ── Alerts ──────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.alert-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

/* ══════════════════════════════════════════════
   TOPBAR
══════════════════════════════════════════════ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--blue);
  border-bottom: none;
  height: 60px;
  flex-shrink: 0;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 32px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  border-radius: 8px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-icon-btn {
  background: none;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: background 0.15s;
}

.topbar-icon-btn:hover { background: rgba(255,255,255,0.15); }

/* ── User menu ───────────────────────────────── */
.user-menu {
  position: relative;
}

.user-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.12);
  border: 1.5px solid rgba(255,255,255,0.25);
  border-radius: 24px;
  padding: 5px 14px 5px 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  transition: border-color 0.2s, background 0.2s;
}

.user-trigger:hover { border-color: rgba(255,255,255,0.6); background: rgba(255,255,255,0.2); }

.user-avatar {
  width: 28px;
  height: 28px;
  background: var(--red);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.caret { font-size: 11px; color: rgba(255,255,255,0.6); }

.user-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.12);
  min-width: 200px;
  overflow: hidden;
  z-index: 200;
}

.user-menu.open .user-dropdown { display: block; }

.dropdown-header {
  padding: 16px 18px 12px;
}

.dropdown-name {
  font-size: 15px;
  font-weight: 700;
  color: #111827;
}

.dropdown-role {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 3px;
}

.dropdown-divider {
  height: 1px;
  background: #f3f4f6;
  margin: 0;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 12px 18px;
  background: none;
  border: none;
  text-align: left;
  font-size: 14px;
  font-family: inherit;
  color: #374151;
  cursor: pointer;
  transition: background 0.15s;
}

.dropdown-item:hover { background: #f9fafb; }

.dropdown-item-danger { color: #b91c1c; }
.dropdown-item-danger:hover { background: #fef2f2; }

/* ══════════════════════════════════════════════
   PORTAL MAIN
══════════════════════════════════════════════ */
.portal-main {
  flex: 1;
  padding: 48px 32px 40px;
}

.portal-container {
  max-width: 1100px;
  margin: 0 auto;
}

/* Welcome row */
.welcome-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

.welcome-title {
  font-size: 26px;
  font-weight: 800;
  color: #111827;
  line-height: 1.3;
}

.welcome-sub {
  font-size: 14px;
  color: #9ca3af;
  margin-top: 6px;
}

.last-used-label {
  font-size: 11px;
  font-weight: 600;
  color: #9ca3af;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.last-used-btn {
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 24px;
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: #374151;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.last-used-btn:hover {
  border-color: var(--blue);
  box-shadow: 0 2px 8px rgba(26,60,138,0.12);
  color: var(--blue);
}

/* System cards */
.systems-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

.sys-card {
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 20px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.sys-card:hover {
  border-color: var(--blue);
  box-shadow: 0 8px 32px rgba(26,60,138,0.12);
  transform: translateY(-3px);
}

.sys-card-icon {
  font-size: 40px;
  margin-bottom: 4px;
  line-height: 1;
}

.sys-card-name {
  font-size: 19px;
  font-weight: 800;
  color: #111827;
}

.sys-card-desc {
  font-size: 13px;
  color: #9ca3af;
  line-height: 1.6;
}

.sys-card-btn {
  margin-top: auto;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 0;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
  text-align: center;
}

.sys-card-btn:hover { background: var(--blue-mid); }

.no-access {
  text-align: center;
  padding: 64px 24px;
  color: #9ca3af;
  font-size: 15px;
  background: #fff;
  border-radius: 16px;
  border: 1.5px dashed #e5e7eb;
}

/* ── Footer ──────────────────────────────────── */
.portal-footer {
  text-align: center;
  padding: 20px 24px;
  font-size: 12px;
  color: #9ca3af;
  background: #fff;
  border-top: 1px solid #e5e7eb;
}

/* ══════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 24px;
}

.modal-card {
  background: #fff;
  border-radius: 18px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.2);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 16px;
  font-weight: 700;
  color: #111827;
}

.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.15s;
}

.modal-close:hover { background: #f3f4f6; color: #374151; }

.modal-body {
  padding: 24px;
}

.pwd-hint {
  font-size: 12px;
  color: #9ca3af;
  background: #f9fafb;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid #f3f4f6;
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 640px) {
  .topbar-inner { padding: 0 16px; }
  .topbar-title { font-size: 14px; }
  .user-name { display: none; }
  .portal-main { padding: 28px 16px; }
  .welcome-title { font-size: 20px; }
  .systems-grid { grid-template-columns: 1fr; }
  .login-card { padding: 32px 24px; }
}
