/* === Base Reset & Fonts === */
@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap');

* {
  box-sizing: border-box; /* Include padding/borders in width */
}

body {
  margin: 0;
  font-family: 'Google Sans', Arial, sans-serif;
  background: #f3f6f9;
  font-size: 1rem;
  color: #1e1e1e;
  height: 100vh;
  width: 100%;
  overflow-x: hidden; /* No horizontal scrolling */
  overscroll-behavior: none; /* Disable mobile pull-to-refresh */
}

body.hidden-until-validated {
  display: none;
}

body.drawer-open {
  overflow: hidden; /* Lock all scrolling when drawer is open */
}

/* === Drawer === */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 80vw;
  max-width: 420px;
  height: 100vh;
  max-height: 100vh;
  background: #fff;
  border-right: 1px solid #d8dde6;
  border-radius: 0 12px 12px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  overflow-x: hidden; /* No horizontal scrolling */
  overflow-y: auto; /* Allow vertical scrolling if content overflows */
}

.drawer.open {
  transform: translateX(0);
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 999;
}

body.drawer-open .drawer-overlay {
  opacity: 1;
  pointer-events: auto;
}

.drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e7e9ee;
}

.drawer__title {
  font-size: 1rem;
  margin: 0;
  color: #000;
}

.drawer__close {
  border: none;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  color: #03363d;
}

.drawer__content {
  padding: 0.5rem 0.75rem;
}

.drawer-menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.drawer-menu li {
  margin: 0.375rem 0;
}

.drawer-menu a,
.drawer-menu button {
  display: block;
  max-width: calc(100% - 1.5rem); /* Account for 0.75rem padding on each side */
  padding: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid #e7e9ee;
  background: #fff;
  color: #1e1e1e;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
  overflow-x: hidden;
}

.drawer-menu a:hover,
.drawer-menu button:hover {
  background: #f4f6f9;
}

@media (max-width: 768px) {
  .drawer {
    width: 80vw;
    max-width: 320px; /* Smaller for mobile */
    overflow-x: hidden;
    overflow-y: auto; /* Allow vertical scrolling if needed */
  }
  body.drawer-open .main {
    overflow: hidden; /* Lock main content */
  }
  body {
    width: 100%;
    overflow-x: hidden;
  }
}

/* === Login Page === */
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: #f3f6f9;
  overflow-x: hidden;
}

.login-box {
  width: 90%;
  max-width: 320px;
  padding: 1.5rem;
  border-radius: 0.5rem;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* === Forms & Inputs === */
input[type="text"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  font-size: 0.9rem;
  color: #333;
  background: #f9fafb;
  border: 1px solid #d8dde6;
  border-radius: 0.25rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus {
  border-color: #009688;
  box-shadow: 0 0 0 3px rgba(0, 150, 136, 0.2);
  outline: none;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg fill='%23333' height='16' viewBox='0 0 24 24' width='16' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
}

.form-ui {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem;
  background: #fff;
  border: 1px solid #d8dde6;
  border-radius: 0.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* === Buttons === */
button,
.form-ui .btn-primary,
.table-ui button {
  height: 2.25rem;
  padding: 0 1rem;
  border: none;
  border-radius: 0.25rem;
  background: #009688;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

button:hover,
.form-ui .btn-primary:hover,
.table-ui button:hover {
  background: #00796b;
}

.special-logout {
  background: linear-gradient(135deg, #d83a00, #ff5f2e);
  padding: 0.5rem;
  max-width: calc(100% - 1.5rem); /* Fit within drawer padding */
  border-radius: 1rem;
  box-shadow: 0 4px 8px rgba(216, 58, 0, 0.3);
  transition: background 0.3s ease, transform 0.2s ease;
}

.special-logout:hover {
  background: linear-gradient(135deg, #b32e00, #e64b1a);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(216, 58, 0, 0.4);
}

.special-logout:active {
  transform: translateY(0);
  box-shadow: 0 3px 6px rgba(216, 58, 0, 0.3);
}

/* === Tables === */
.table-wrapper {
  margin-top: 1rem;
  background: #fff;
  border: 1px solid #d8dde6;
  border-radius: 0.5rem;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow-x: hidden;
  overflow-y: visible; /* Allow dropdown to render outside wrapper */
  position: relative; /* Stable positioning context */
}

.table-ui {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  position: relative;
  table-layout: fixed; /* Stabilize column widths */
}

.table-ui thead {
  background: #f4f6f9;
}

.table-ui thead th {
  text-align: left;
  padding: 0.75rem;
  font-weight: 600;
  color: #333;
  border-bottom: 1px solid #d8dde6;
}

.table-ui tbody tr:nth-child(odd) {
  background: #fafafa;
}

.table-ui tbody tr:hover {
  background: #f0f7f7;
}

.table-ui td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid #e4e7eb;
  min-width: 0;
  position: relative;
}

.table-ui td:nth-child(2) {
  min-width: 140px; /* Increased for select stability */
  min-height: 3rem; /* More room for dropdown */
}

.table-ui select {
  height: 2rem;
  padding: 0 1.5rem 0 0.5rem;
  font-size: 0.85rem;
  background-image: url("data:image/svg+xml;utf8,<svg fill='%23333' height='14' viewBox='0 0 24 24' width='14' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
  background-position: right 0.5rem center;
  background-size: 0.875rem;
  position: relative;
  width: 100%;
  display: block;
  z-index: 1000; /* High z-index to prioritize dropdown */
  scroll-margin-top: 4rem; /* Ensure select is in view when focused */
}

/* === Main Layout === */
.main {
  margin-left: 0;
  background: #f5f6f7;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto; /* Allow vertical scrolling when drawer is closed */
  scroll-padding-top: 4rem; /* Ensure select is in view when focused */
}

.main-panel,
.main-panel-detail {
  background: #fff;
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  padding: 1.5rem;
  margin: 1.5rem;
  max-width: 100%;
  overflow-x: hidden;
  position: relative; /* Stable context for dropdown */
  overflow-y: visible; /* Prevent clipping dropdown */
}

.main-panel-detail {
  flex: 1; /* Grow to fill remaining space */
}

.main-panel h2,
.main-panel-detail h2 {
  margin-top: 0;
  font-size: 1.25rem;
  color: #1e1e1e;
}

.main-panel h3 {
  margin-top: 1rem;
  font-size: 1rem;
  color: #1e1e1e;
}

.main-panel pre {
  background: #f4f6f9;
  padding: 0.75rem;
  border-radius: 0.25rem;
  border: 1px solid #d8dde6;
  overflow-x: auto;
}

/* === Header === */
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #03363d;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #d8dde6;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow-x: hidden;
}

.main-header h1 {
  font-size: 1.25rem;
  color: #fff;
  margin: 0;
}

.main-header .actions {
  display: flex;
  gap: 0.5rem;
}

.main-header .actions button {
  padding: 0.5rem 0.75rem;
  background: #fff;
  color: #000;
  border: none;
  border-radius: 0.25rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.main-header .actions button:hover {
  background: #005fb2;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  height: 2rem;
  width: auto;
}

@media (max-width: 768px) {
  .main-header {
    gap: 0.75rem;
    overflow-x: hidden;
  }
  .drawer-toggle {
    order: -1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.25rem;
    padding: 0.375rem 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
  }
  .header-logo {
    height: 1.5rem;
  }
}

/* === Sidebar & Side Panel === */
.sidebar,
.side-panel {
  background: #fff;
  padding: 1rem;
  border-radius: 0.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow-x: hidden;
}

.sidebar {
  width: 90%;
  max-width: 20rem;
  border-right: 1px solid #d8dde6;
}

.side-panel {
  width: 20%;
  max-width: 20rem;
}

.sidebar h3,
.side-panel h3 {
  margin-top: 0;
  font-size: 1rem;
  color: #0070d2;
}

.sidebar ul,
.side-panel ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar li,
.side-panel li {
  padding: 0.625rem;
  margin: 0.25rem 0;
  cursor: pointer;
  border-radius: 0.25rem;
}

.sidebar li:hover,
.side-panel li:hover {
  background: #f4f6f9;
}

.nav-back {
  display: inline-block;
  margin-bottom: 1rem;
  text-decoration: none;
  color: #0070d2;
  font-size: 0.9rem;
}

.nav-back:hover {
  text-decoration: underline;
}

/* === Tables === */
.table-wrapper {
  margin-top: 1rem;
  background: #fff;
  border: 1px solid #d8dde6;
  border-radius: 0.5rem;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow-x: hidden;
  overflow-y: visible; /* Allow dropdown to render outside wrapper */
  position: relative; /* Stable positioning context */
}

.table-ui {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  position: relative;
  table-layout: fixed; /* Stabilize column widths */
}

.table-ui thead {
  background: #f4f6f9;
}

.table-ui thead th {
  text-align: left;
  padding: 0.75rem;
  font-weight: 600;
  color: #333;
  border-bottom: 1px solid #d8dde6;
}

.table-ui tbody tr:nth-child(odd) {
  background: #fafafa;
}

.table-ui tbody tr:hover {
  background: #f0f7f7;
}

.table-ui td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid #e4e7eb;
  min-width: 0;
  position: relative;
}

.table-ui td:nth-child(2) {
  min-width: 140px; /* Increased for select stability */
  min-height: 3rem; /* More room for dropdown */
}

.table-ui select {
  height: 2rem;
  padding: 0 1.5rem 0 0.5rem;
  font-size: 0.85rem;
  background-image: url("data:image/svg+xml;utf8,<svg fill='%23333' height='14' viewBox='0 0 24 24' width='14' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
  background-position: right 0.5rem center;
  background-size: 0.875rem;
  position: relative;
  width: 100%;
  display: block;
  z-index: 1000; /* High z-index to prioritize dropdown */
  scroll-margin-top: 4rem; /* Ensure select is in view when focused */
}

/* === Main Layout === */
.main {
  margin-left: 0;
  background: #f5f6f7;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto; /* Allow vertical scrolling when drawer is closed */
  scroll-padding-top: 4rem; /* Ensure select is in view when focused */
}

.main-panel,
.main-panel-detail {
  background: #fff;
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  padding: 1.5rem;
  margin: 1.5rem;
  max-width: 100%;
  overflow-x: hidden;
  position: relative; /* Stable context for dropdown */
  overflow-y: visible; /* Prevent clipping dropdown */
}

.main-panel-detail {
  flex: 1; /* Grow to fill remaining space */
}

.main-panel h2,
.main-panel-detail h2 {
  margin-top: 0;
  font-size: 1.25rem;
  color: #1e1e1e;
}

.main-panel h3 {
  margin-top: 1rem;
  font-size: 1rem;
  color: #1e1e1e;
}

.main-panel pre {
  background: #f4f6f9;
  padding: 0.75rem;
  border-radius: 0.25rem;
  border: 1px solid #d8dde6;
  overflow-x: auto;
}

/* === Detail Container === */
.detail-container {
  display: flex;
  height: calc(100vh - 3rem); /* Adjust for header */
  overflow-x: hidden;
  overflow-y: visible; /* Allow dropdown to render fully */
}

@media (max-width: 768px) {
  .detail-container {
    flex-direction: column; /* Stack vertically on mobile */
    overflow-y: visible; /* Allow dropdown to render fully */
  }
  .side-panel {
    width: 100%;
    max-width: none;
    margin: 1rem;
  }
  .main-panel-detail {
    width: 100%;
    max-width: none;
    margin: 0 1rem 1rem;
    overflow-y: visible;
  }
}