* {
  box-sizing: border-box;
}

body.auth-checking {
  visibility: hidden;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f5f7fb;
  color: #111827;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: 250px;
  background: white;
  border-right: 1px solid #e5e7eb;
  padding: 20px 12px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 0 10px 25px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #10bbd5;
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand h3 {
  margin: 0;
  line-height: 1.15;
  font-size: 16px;
}

.brand p {
  margin: 6px 0 0;
  color: #9ca3af;
  font-size: 12px;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-item {
  border: 0;
  background: transparent;
  padding: 14px;
  border-radius: 14px;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  color: #4b5563;
  cursor: pointer;
}

.menu-item.active {
  color: white;
  background: linear-gradient(90deg, #2f80ed, #10bbd5);
}

/* MAIN */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 78px;
  background: white;
  border-bottom: 1px solid #e5e7eb;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
}

.topbar p {
  margin: 2px 0 0;
  color: #6b7280;
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb;
  cursor: pointer;
}

.user-menu {
  position: relative;
}

.user-btn {
  border: 0;
  background: #f3f4f6;
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  cursor: pointer;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #0ea5e9;
  color: white;
  display: grid;
  place-items: center;
}

.dropdown {
  position: absolute;
  top: 50px;
  right: 0;
  width: 190px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 10px 25px rgba(0,0,0,.12);
  display: none;
  overflow: hidden;
  z-index: 10;
}

.dropdown.show {
  display: block;
}

.dropdown button {
  width: 100%;
  border: 0;
  background: white;
  padding: 13px 14px;
  text-align: right;
  font-weight: 700;
  cursor: pointer;
}

.dropdown button:hover {
  background: #f9fafb;
}

.dropdown .danger {
  color: #ef4444;
}

/* CONTENT */
.content {
  flex: 1;
  padding: 18px;
  overflow: hidden;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 18px;
}

.page-head h2 {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
}

.page-head p {
  margin: 6px 0 0;
  color: #6b7280;
  font-size: 14px;
}

.primary-btn {
  border: 0;
  background: #10bbd5;
  color: white;
  border-radius: 14px;
  padding: 14px 18px;
  font-weight: 800;
  cursor: pointer;
}

.primary-btn:hover {
  background: #0aa7bf;
}

/* TABLE */
.list-search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
}

.list-search-input {
  position: relative;
  flex: 1;
}

.list-search-input span {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #64748b;
  font-size: 22px;
  pointer-events: none;
}

.list-search-input input {
  width: 100%;
  height: 48px;
  padding: 0 16px 0 48px;
  border: 1px solid #d8dee8;
  border-radius: 12px;
  background: #f8fafc;
  outline: none;
  font: inherit;
}

.list-search-input input:focus {
  border-color: #2458e6;
  box-shadow: 0 0 0 3px rgba(36, 88, 230, .1);
  background: #fff;
}

.list-search-count {
  display: flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
  color: #64748b;
  font-size: 13px;
}

.list-search-count strong {
  color: #0f172a;
  font-size: 17px;
}

.clear-search-btn {
  height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: #eef2ff;
  color: #2458e6;
  font-weight: 800;
  cursor: pointer;
}

.table-box {
  height: calc(100vh - 175px);
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  box-shadow: 0 4px 14px rgba(0,0,0,.05);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.table-header,
.table-row {
  display: grid;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid #f1f5f9;
}

.table-header {
  color: #6b7280;
  font-size: 13px;
  font-weight: 800;
}

.table-body {
  overflow: auto;
  flex: 1;
}

.table-row {
  font-size: 14px;
}

.bold {
  font-weight: 800;
}

.muted {
  color: #6b7280;
}

.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.action-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.edit {
  background: #eef4ff;
  color: #3b82f6;
}

.delete {
  background: #fff1f2;
  color: #ef4444;
}

.green {
  background: #ecfdf5;
  color: #10b981;
}

.chip {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  background: #f3f4f6;
  color: #6b7280;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.status-dot {
  width: 18px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid #22c55e;
  background: #dcfce7;
  position: relative;
}

.status-dot::after {
  content: "";
  width: 5px;
  height: 5px;
  background: #22c55e;
  border-radius: 50%;
  position: absolute;
  top: 1.5px;
  right: 2px;
}

.status.off {
  color: #6b7280;
}

.status.off .status-dot {
  border-color: #9ca3af;
  background: #f3f4f6;
}

.status.off .status-dot::after {
  background: #9ca3af;
  left: 2px;
  right: auto;
}

/* FORM */
select,
input,
textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  padding: 12px;
  font-size: 14px;
  outline: none;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: grid;
  place-items: center;
  z-index: 100;
}

.hidden {
  display: none;
}

.modal-card {
  width: 460px;
  max-width: calc(100vw - 30px);
  background: white;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,.18);
}

.modal-card h3 {
  margin: 0 0 16px;
  font-size: 22px;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.list-search-bar + .table-box {
  height: calc(100vh - 260px);
}

@media (max-width: 720px) {
  .list-search-bar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .list-search-input {
    flex-basis: 100%;
  }
}

/* FULL-PAGE CREATE / EDIT FORMS */
.form-page {
  min-height: calc(100vh - 120px);
  padding: 4px 0 36px;
}

.form-page-nav {
  margin-bottom: 18px;
}

.back-btn {
  border: 0;
  background: transparent;
  color: #475569;
  font-size: 14px;
  font-weight: 800;
  padding: 10px 0;
  cursor: pointer;
}

.back-btn:hover {
  color: #0f172a;
}

.form-page-card {
  width: 100%;
  max-width: 980px;
  min-height: 520px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 24px;
  padding: 32px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .07);
}

.form-page-card h3 {
  margin: 0 0 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid #edf0f5;
  color: #111827;
  font-size: 30px;
  font-weight: 900;
}

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

.form-page-card .form > textarea,
.form-page-card .form > .switch-line,
.form-page-card .form > .modal-actions,
.form-page-card .form > .form-row,
.form-page-card .form > .field-wide {
  grid-column: 1 / -1;
}

.field-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #182033;
  font-size: 14px;
  font-weight: 800;
}

.field-control small {
  color: #8a94a6;
  font-weight: 600;
}

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

.form-page-card input,
.form-page-card select,
.form-page-card textarea {
  min-height: 54px;
  border-radius: 14px;
  font-size: 15px;
}

.form-page-card textarea {
  min-height: 130px;
}

.form-page-card .switch-line {
  justify-content: space-between;
  min-height: 52px;
  padding: 12px 15px;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #f8fafc;
}

.form-page-card .switch-line > span {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.form-page-card .switch-line small {
  color: #7b8495;
  font-weight: 500;
}

.form-page-card .switch-line input {
  width: 20px;
  min-height: 20px;
}

.form-page-card .modal-actions {
  padding-top: 22px;
  border-top: 1px solid #edf0f5;
}

.cancel-btn {
  border: 0;
  background: #f3f4f6;
  color: #111827;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
}

.switch-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: #6b7280;
  font-size: 15px;
}

.coming {
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
}

/* GRIDS */
.grid-template-groups {
  grid-template-columns: 2fr 4fr 1fr 120px;
}

.grid-categories {
  grid-template-columns: 2fr 4fr 2fr 120px;
}

.grid-materials {
  grid-template-columns: 3fr 2fr 2fr 2fr 3fr 120px;
}

.grid-fields {
  grid-template-columns: 3fr 2fr 2fr 2fr 120px;
}

/* LOGIN */
.login-page {
  min-height: 100vh;
  background: #f5f7fb;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 390px;
  max-width: 100%;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 900;
}

.login-card p {
  margin: 0 0 10px;
  color: #6b7280;
}

.login-msg {
  min-height: 20px;
  font-size: 14px;
  color: #ef4444;
  font-weight: 700;
}

@media (max-width: 850px) {
  .app {
    min-height: 100vh;
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .brand h3 {
    line-height: 1.1;
  }

  .menu {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .menu-item {
    flex: 0 0 auto;
    white-space: nowrap;
    margin-bottom: 0;
  }

  .main {
    min-width: 0;
  }

  .topbar {
    min-height: 78px;
    height: auto;
    padding: 12px 16px;
  }

  .topbar h1,
  .page-head h2 {
    font-size: 24px;
  }

  .table-box {
    overflow-x: auto;
  }

  .table-header,
  .table-row {
    min-width: 850px;
  }

  .form-page-card {
    min-height: 0;
    padding: 22px;
    border-radius: 20px;
  }

  .form-page-card h3 {
    font-size: 25px;
  }

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

  .form-page-card .form > * {
    grid-column: 1 !important;
  }
}

@media (max-width: 540px) {
  .content {
    padding: 14px;
  }

  .topbar p,
  .top-actions > .icon-btn {
    display: none;
  }

  .topbar h1 {
    font-size: 21px;
  }

  .user-btn {
    padding: 8px;
    font-size: 0;
  }

  .page-head {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
  }

  .page-head .primary-btn {
    width: 100%;
  }

  .form-page-card {
    padding: 18px;
  }

  .form-page-card .form-row {
    grid-template-columns: 1fr;
  }

  .form-page-card .modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .form-page-card .modal-actions button {
    min-height: 50px;
  }
}
