:root {
  --bg: #0f1419;
  --card: #1a2332;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --danger: #ef4444;
  --ok: #22c55e;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 1rem;
  max-width: 1100px;
  margin-inline: auto;
  /* Tránh Safari iOS zoom khi double-tap */
  touch-action: manipulation;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.site-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
}

.site-title-wrap {
  min-width: 0;
}

.site-title-wrap h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.3;
}

.site-title-wrap .subtitle {
  color: var(--muted);
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  line-height: 1.35;
}

#logout-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-top: 1rem;
}

label { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; }

/* Safari iOS tự zoom nếu font input < 16px — luôn >= 16px */
input,
select,
textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-appearance: none;
  appearance: none;
}

button {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 600;
}
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
button.danger { background: var(--danger); }
button.small { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 1rem 0; align-items: center; }
.tabs button.active { background: var(--accent); }

.hidden { display: none !important; }
.error { color: var(--danger); }
.muted { color: var(--muted); font-size: 0.9rem; }

.list-view {
  display: flex;
  flex-direction: column;
}

.list-card,
.request-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.list-card:last-child,
.request-card:last-child {
  margin-bottom: 0;
}

.list-card > p,
.request-card > p {
  margin: 0.25rem 0;
}

.list-card-head,
.license-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.list-card-head strong,
.license-head strong {
  font-size: 1rem;
}

.request-card h4 { margin: 0 0 0.5rem; }
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  background: #334155;
}
.badge.plus { background: #1e3a5f; color: #93c5fd; }
.badge.ok { background: #14532d; color: #86efac; }
.badge.warn { background: #713f12; color: #fcd34d; }
.badge.danger { background: #7f1d1d; color: #fca5a5; }

.tab-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.tab-header h2 { margin: 0; flex: 1 1 auto; min-width: 140px; }

.tab-header-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  flex: 1 1 auto;
  min-width: 0;
}

.tab-header-row .search-input {
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
}

.staff-tab-header {
  flex-direction: column;
  align-items: stretch;
}

.staff-tab-header h2 {
  flex: none;
}

#staff-add-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.search-input {
  flex: 1 1 220px;
  max-width: 360px;
  width: auto;
  min-width: 0;
  min-height: 0;
  height: auto;
  margin: 0 !important;
  padding: 0.55rem 0.75rem !important;
  font-size: 16px !important;
  display: block;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

input[type="search"].search-input {
  -webkit-appearance: none;
  appearance: none;
}

input[type="search"].search-input::-webkit-search-decoration,
input[type="search"].search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

button.small:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.data-table { margin-top: 0.25rem; }

.actions-cell {
  white-space: nowrap;
}
.actions-cell button {
  margin-right: 0.35rem;
  margin-bottom: 0.25rem;
}

.tabs button.hidden { display: none; }

table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 1rem;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  padding: 1.25rem;
  max-width: 420px;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog menu { display: flex; gap: 0.5rem; justify-content: flex-end; padding: 0; margin: 1rem 0 0; }

/* --- UI dialog (alert / confirm) --- */
.ui-dialog {
  border: none;
  padding: 0;
  max-width: min(440px, calc(100vw - 2rem));
  background: transparent;
  box-shadow: none;
}
.ui-dialog::backdrop {
  background: rgba(8, 12, 18, 0.72);
  backdrop-filter: blur(4px);
}
.ui-dialog-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem 1.5rem 1.25rem;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}
.ui-dialog--error .ui-dialog-icon { color: #f87171; background: rgba(239, 68, 68, 0.15); }
.ui-dialog--warning .ui-dialog-icon { color: #fbbf24; background: rgba(245, 158, 11, 0.15); }
.ui-dialog--success .ui-dialog-icon { color: #4ade80; background: rgba(34, 197, 94, 0.15); }
.ui-dialog--info .ui-dialog-icon { color: #60a5fa; background: rgba(59, 130, 246, 0.15); }

.ui-dialog-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}
.ui-dialog-title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 600;
}
.ui-dialog-body {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-line;
}
.ui-dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 0;
  margin: 0;
  flex-wrap: wrap;
}
.ui-dialog-actions button.primary {
  background: var(--accent);
  min-width: 5.5rem;
}
.ui-dialog-actions button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

/* --- Login --- */
.login-form .login-submit {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.65rem 1rem;
  font-size: 1rem;
}

.password-label { display: block; }

.password-field {
  position: relative;
  display: block;
  margin-top: 0.35rem;
}

.password-field input {
  width: 100%;
  margin-top: 0;
  padding-right: 3.25rem;
  font-size: 16px;
}

.password-field.inline-password {
  display: flex;
  align-items: stretch;
  margin-top: 0;
}

.password-field.inline-password input {
  flex: 1;
  min-width: 0;
}

.password-toggle {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  min-width: 2.5rem;
  height: 2rem;
  padding: 0 0.4rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.password-field.inline-password .password-toggle {
  position: static;
  transform: none;
  flex-shrink: 0;
  align-self: center;
  background: var(--bg);
  border: 1px solid var(--border);
  margin-left: 0.25rem;
}

.password-toggle:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}

.table-scroll table {
  min-width: 560px;
}

/* --- Mobile --- */
@media (max-width: 640px) {
  body {
    padding:
      max(0.75rem, env(safe-area-inset-top))
      max(0.75rem, env(safe-area-inset-right))
      max(0.75rem, env(safe-area-inset-bottom))
      max(0.75rem, env(safe-area-inset-left));
  }

  header h1 {
    font-size: 1.25rem;
  }

  .card {
    padding: 1rem;
    border-radius: 10px;
  }

  .tabs {
    gap: 0.35rem;
    margin: 0.75rem 0;
  }

  .tabs button {
    flex: 1 1 calc(50% - 0.35rem);
    min-width: 0;
    padding: 0.5rem 0.5rem;
    font-size: 0.85rem;
  }

  input,
  select,
  textarea,
  .search-input {
    font-size: 16px !important;
  }

  .site-header {
    align-items: flex-start;
  }

  .site-logo {
    width: 36px;
    height: 36px;
  }

  .site-title-wrap h1 {
    font-size: 1.1rem;
  }

  .tab-header {
    flex-direction: column;
    align-items: stretch;
  }

  .tab-header h2 {
    font-size: 1.1rem;
    flex: 0 0 auto;
    width: 100%;
  }

  /* flex: 1 1 220px trong cột sẽ giãn CHIỀU CAO → ô vuông to */
  .search-input {
    flex: none;
    width: 100%;
    max-width: 100%;
    height: 2.75rem;
    min-height: 2.75rem;
    max-height: 2.75rem;
  }

  .tab-header-row {
    flex-direction: row;
    align-items: center;
  }

  .tab-header-row .search-input {
    flex: 1;
    width: auto;
  }

  #staff-add-btn {
    height: 2.75rem;
    padding-inline: 0.75rem;
  }

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

  .action-row button {
    flex: 1 1 calc(50% - 0.4rem);
    min-width: 7rem;
  }

  .actions-cell {
    white-space: normal;
  }

  .actions-cell button {
    display: inline-block;
    margin-bottom: 0.35rem;
  }

  dialog:not(.ui-dialog) {
    width: calc(100vw - 1.5rem);
    max-width: none;
  }

  dialog menu {
    flex-direction: column-reverse;
  }

  dialog menu button {
    width: 100%;
  }

  .ui-dialog-actions {
    flex-direction: column-reverse;
  }

  .ui-dialog-actions button {
    width: 100%;
  }
}

@media (max-width: 400px) {
  .action-row button {
    flex: 1 1 100%;
  }
}
