:root {
  --primary: #1f9bd1;
  --primary-dark: #1667b3;
  --primary-light: #73c9e5;
  --bg: #f4f8fb;
  --text: #1e3a5f;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
  font-family: Arial, sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

body.guest-mode {
  overflow-y: auto;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--primary-dark), var(--primary));
  color: var(--white);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  text-align: center;
}

.brand img {
  width: 90px;
  height: 90px;
  object-fit: contain;
  background: var(--white);
  border-radius: 50%;
  padding: 6px;
}

.brand h1 {
  font-size: 1.2rem;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-group {
  display: grid;
  gap: 4px;
  border-radius: 10px;
  padding: 3px;
  transition: background 0.2s ease;
}

.menu-group.expanded {
  background: rgba(255, 255, 255, 0.07);
}

.menu-subnav {
  display: grid;
  gap: 4px;
  margin-left: 8px;
  padding-left: 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.28);
}

.menu-subitem {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.04);
  color: #ffffff;
  border-radius: 6px;
  padding: 4px 8px;
  text-align: left;
  font-size: 0.76rem;
  line-height: 1.2;
  cursor: pointer;
  transition: all 0.2s ease;
}

.menu-subitem:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.38);
}

.menu-subitem.active {
  background: #ffffff;
  color: #1667b3;
  border-color: #ffffff;
  font-weight: 700;
}

.menu-item {
  background: rgba(255, 255, 255, 0.14);
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease;
  border: none;
  color: var(--white);
  text-align: left;
  width: 100%;
  font-size: 0.95rem;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.menu-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-chevron {
  font-size: 0.78rem;
  opacity: 0.9;
  transition: transform 0.2s ease;
}

.menu-group.expanded .menu-chevron {
  transform: rotate(180deg);
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.24);
}

.menu-item:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

.menu-item.active {
  background: rgba(255, 255, 255, 0.36);
  font-weight: bold;
}

.content {
  padding: 24px;
  height: 100vh;
  overflow-y: auto;
}

.panel {
  background: var(--white);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 4px 18px rgba(22, 103, 179, 0.08);
}

.form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  max-width: 450px;
}

input, select, button {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #dbe4ef;
}

.btn {
  background: var(--primary-dark);
  color: var(--white);
  border: none;
  cursor: pointer;
}

.btn-outline {
  border: 1px solid var(--white);
  background: transparent;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.tab {
  background: #dceef7;
  border: none;
}

.tab.active {
  background: var(--primary);
  color: var(--white);
}

.hidden {
  display: none !important;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-page-back {
  background: #ffffff;
  color: var(--primary-dark);
  border: 1px solid #c9d8ea;
}

.badge {
  background: #dceef7;
  color: var(--primary-dark);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: bold;
}

.kpi-grid {
  margin: 16px 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.kpi {
  background: linear-gradient(120deg, var(--primary-light), var(--primary));
  color: var(--white);
  padding: 12px;
  border-radius: 10px;
}

.kpi h4 {
  margin: 0 0 6px;
}

.kpi p {
  margin: 0;
  font-size: 1.2rem;
  font-weight: bold;
}

.chart-panel {
  margin-bottom: 16px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 10px;
}

.chart-grid-four {
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

@media (max-width: 900px) {
  .chart-grid-four {
    grid-template-columns: 1fr;
  }
}

.chart-card {
  background: #f8fbff;
  border: 1px solid #dbe4ef;
  border-radius: 10px;
  padding: 12px;
}

.chart-card h4 {
  margin: 0 0 6px;
  color: var(--primary-dark);
}

.chart-desc {
  margin: 0 0 10px;
  color: #5a6f88;
  font-size: 0.9rem;
  line-height: 1.35;
}

.chart-card canvas {
  width: 100%;
  height: 280px;
  display: block;
}

.actions {
  display: block;
}

.actions-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--primary-dark);
}

.actions-form .btn {
  grid-column: 1 / -1;
  justify-self: start;
}

pre {
  white-space: pre-wrap;
  background: #f2f7fc;
  padding: 12px;
  border-radius: 10px;
  margin-top: 12px;
}

.invoice-card {
  margin-top: 14px;
  border: 1px solid #dbe4ef;
}

.employee-table-wrap {
  margin-top: 14px;
  overflow-x: hidden;
}

.employee-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  table-layout: fixed;
}

.employee-table th,
.employee-table td {
  border: 1px solid #dbe4ef;
  padding: 7px 8px;
  text-align: left;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  vertical-align: top;
}

.employee-table th {
  background: #f2f7fc;
  color: #1e3a5f;
  font-size: 0.82rem;
}

.delete-employee-btn {
  color: #b42318;
  border: 1px solid #f6d0cc;
  background: #fff5f5;
}

.user-management-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.module-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.overview-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.overview-card {
  border: 1px solid #dbe4ef;
}

.overview-card h4 {
  margin: 0 0 8px;
  color: var(--primary-dark);
}

.overview-card p {
  margin: 0 0 12px;
  color: #5a6f88;
}

.overview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stock-subnav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stock-subnav-btn {
  border: 1px solid #c7d9ec;
  background: #eef5fc;
  color: #1667b3;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}

.stock-subnav-btn.active {
  background: #1667b3;
  color: #fff;
  border-color: #1667b3;
}

.stock-form-title {
  margin: 10px 0 8px;
  color: #1667b3;
}

.asset-balance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.asset-balance-item {
  border: 1px solid #dbe4ef;
  border-radius: 8px;
  background: #f7fbff;
  padding: 10px;
  display: grid;
  gap: 4px;
}

.asset-balance-item span {
  color: #5a6f88;
  font-size: 0.9rem;
}

.asset-balance-item strong {
  color: #1667b3;
  font-size: 1.05rem;
}

.overview-modal {
  position: fixed;
  inset: 0;
  background: rgba(30, 58, 95, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 16px;
}

.overview-modal-content {
  width: min(740px, 100%);
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #dbe4ef;
  padding: 16px;
  box-shadow: 0 12px 30px rgba(22, 103, 179, 0.2);
}

@media (max-width: 1024px) {
  .app {
    grid-template-columns: 230px 1fr;
  }

  .content {
    padding: 16px;
  }
}

@media (max-width: 800px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    gap: 10px;
    height: auto;
    overflow: visible;
  }

  .menu {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .menu-item {
    flex: 1 1 130px;
    text-align: center;
  }

  .actions-form {
    grid-template-columns: 1fr;
  }

  .header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .content {
    height: auto;
    overflow: visible;
  }
}

/* Welcome & login experience */
.welcome-page,
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 20px;
  position: relative;
}

.welcome-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(115, 201, 229, 0.35), transparent 40%),
    radial-gradient(circle at 85% 10%, rgba(22, 103, 179, 0.25), transparent 35%),
    linear-gradient(135deg, #e8f4fc 0%, #f4f8fb 45%, #dceef7 100%);
  z-index: 0;
}

.welcome-inner,
.login-card {
  position: relative;
  z-index: 1;
  width: min(980px, 100%);
}

.welcome-inner {
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #d7e6f3;
  border-radius: 22px;
  padding: 48px 36px 40px;
  box-shadow: 0 22px 48px rgba(22, 103, 179, 0.14);
}

@keyframes logoPop {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 12px 32px rgba(22, 103, 179, 0.22);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 20px 44px rgba(22, 103, 179, 0.35);
  }
}

.welcome-logo {
  width: clamp(160px, 22vw, 220px);
  height: clamp(160px, 22vw, 220px);
  object-fit: contain;
  border-radius: 50%;
  background: #fff;
  padding: 14px;
  border: 4px solid var(--primary-light);
  margin: 0 auto 20px;
  display: block;
  animation: logoPop 2.4s ease-in-out infinite;
}

.welcome-heading {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.welcome-desc {
  margin: 18px auto 0;
  max-width: 520px;
  color: #35577f;
  font-size: clamp(1.15rem, 2.4vw, 1.45rem);
  font-weight: 600;
  line-height: 1.4;
}

.btn-welcome-cta {
  margin-top: 32px;
  min-width: 240px;
  font-size: 1.08rem;
  padding: 14px 28px;
}

.login-logo {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border-radius: 50%;
  background: #fff;
  padding: 8px;
  border: 2px solid #d7e6f3;
}

.login-page {
  background: linear-gradient(160deg, #dceef7, #f4f8fb);
}

.login-card {
  max-width: 460px;
  margin: 0 auto;
}

.login-logo {
  display: block;
  margin: 0 auto 10px;
}

.login-role-title {
  margin: 0 0 18px;
  text-align: center;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 800;
  color: var(--primary-dark);
}

.login-form {
  max-width: none;
  margin-top: 8px;
}

.login-form .field {
  display: grid;
  gap: 6px;
}

.login-form label {
  font-size: 0.9rem;
  color: #35577f;
  font-weight: 600;
}

.password-field-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field-wrap input {
  width: 100%;
  padding-right: 46px;
}

.password-toggle-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--primary-dark);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  line-height: 0;
}

.password-toggle-btn:hover {
  background: #e8f4fc;
}

.password-toggle-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.password-toggle-icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.password-toggle-icon.hidden {
  display: none;
}

.btn-back-login {
  margin-bottom: 10px;
  color: var(--primary-dark);
  border-color: #c9d8ea;
  background: #fff;
}

.auth-message {
  margin-top: 10px;
  min-height: 0;
  color: #c0392b;
  text-align: center;
  font-size: 0.92rem;
}

.auth-message:empty {
  display: none;
}

.role-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
}

.role-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 50, 84, 0.45);
}

.role-modal-content {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}

.role-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: #476385;
}

.role-modal-desc {
  color: #4f6b88;
  margin-top: 0;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.role-card {
  border: 1px solid #cfe0f0;
  background: #f7fbff;
  border-radius: 10px;
  padding: 16px 14px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.role-card:hover,
.role-card:focus-visible {
  border-color: var(--primary);
  background: #edf7fd;
  transform: translateY(-1px);
}

body:not(.guest-mode) {
  height: 100vh;
  overflow: hidden;
}

@media (max-width: 900px) {
  .role-grid {
    grid-template-columns: 1fr;
  }
}
