/* ======================================================================
   PROFESSIONAL STOCK TAKE UI
====================================================================== */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #17212f;
  --muted: #6b7280;
  --border: #e6e8ee;
  --accent: #b30000;
  --danger: #8f0000;
  --secondary: #ffffff;
  --success: #16a34a;
  --shadow: 0 8px 20px rgba(17, 24, 39, 0.07);
  --shadow-strong: 0 14px 34px rgba(17, 24, 39, 0.11);
  --radius: 14px;
  --transition: all 0.22s ease;
}

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

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
  border-radius: 12px;
  padding: 0.95rem 1.3rem;
  min-height: 50px;
  font-weight: 700;
  transition: transform 0.16s ease, background-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(179, 0, 0, 0.35);
  outline-offset: 2px;
}

button:hover {
  transform: translateY(-1px);
  opacity: 0.96;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 8px 16px rgba(179, 0, 0, 0.2);
  font-weight: 750;
}

.btn-secondary {
  background: #fff;
  color: var(--accent);
  border: 1px solid rgba(179, 0, 0, 0.35);
  font-weight: 700;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-wide {
  width: 100%;
  max-width: 320px;
}

.hidden {
  display: none !important;
  pointer-events: none !important;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow-y: auto;
  transition: opacity 0.24s ease, transform 0.24s ease;
  opacity: 0;
  transform: translateY(12px);
}

.screen:not(.hidden) {
  opacity: 1;
  transform: translateY(0);
}

/* ======================================================================
   SPLASH SCREEN
====================================================================== */

#splashScreen {
  background: linear-gradient(135deg, #f5f6f8, #ffffff);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.5s ease both;
}

.splash-card {
  width: 100%;
  max-width: 320px;
  padding: 2.2rem 1.4rem;
  border-radius: 18px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-strong);
  text-align: center;
  animation: fadeUp 0.6s ease both;
}

.splash-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  margin-bottom: 1.4rem;
}

.logo {
  width: 92px;
  height: auto;
  margin-bottom: 0.55rem;
  animation: fadeUp 0.6s ease both;
}

.eyebrow {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

h1,
h2,
h3 {
  color: var(--text);
  margin: 0;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  line-height: 1.06;
  letter-spacing: 0;
  white-space: nowrap;
}

.subtitle,
.card-copy,
.splash-note {
  color: var(--muted);
  line-height: 1.65;
}

.subtitle {
  margin-top: 0.7rem;
  margin-bottom: 0.2rem;
  max-width: 28rem;
  margin-left: auto;
  margin-right: auto;
  color: #8a93a2;
  line-height: 1.55;
}

.btn-hero {
  width: 100%;
  min-height: 52px;
  padding: 1rem 1.35rem;
  margin-top: 1.1rem;
  border-radius: 12px;
  font-size: 1rem;
  letter-spacing: 0.04em;
  transition: all 0.2s ease;
}

.btn-hero:hover {
  transform: scale(1.03);
}

.btn-hero:active {
  transform: scale(0.98);
}

.splash-note {
  margin-top: 1rem;
  font-size: 0.88rem;
}

/* ======================================================================
   AUTH SCREEN
====================================================================== */

.screen-panel {
  width: min(500px, 100%);
}

#loginScreen {
  background: linear-gradient(160deg, #f6f7fa 0%, #ffffff 55%, #fff7f7 100%);
}

.auth-card {
  border-radius: 16px;
  padding: 2.1rem;
  background: #fff;
  border: 1px solid #e7e9ef;
  box-shadow: 0 18px 38px rgba(17, 24, 39, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: fadeInUp 0.34s ease both;
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, #8f0000, #b30000, #d92929);
}

.auth-form {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1.1rem 0 1.55rem;
}

.auth-field {
  display: grid;
  gap: 0.42rem;
  text-align: left;
}

.auth-card input,
.auth-input {
  width: 100%;
  padding: 0.95rem 0.95rem;
  min-height: 50px;
  border-radius: 12px;
  border: 1px solid #d5d9e2;
  background: #fcfdff;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.auth-card input:focus,
.auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(179, 0, 0, 0.2);
  background: #fff;
}

.auth-card label,
.field-card label {
  font-size: 0.8rem;
  margin-bottom: 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #7b8494;
}

#loginScreen .section-header {
  margin-bottom: 0.35rem;
}

#loginScreen .section-header h2 {
  font-size: 1.45rem;
  font-weight: 760;
}

#loginScreen .btn-wide {
  max-width: 100%;
}

#loginScreen #loginBtn {
  min-height: 52px;
  letter-spacing: 0.01em;
  box-shadow: 0 10px 20px rgba(179, 0, 0, 0.2);
}

/* ======================================================================
   MAIN APP SCREEN
====================================================================== */

.main-shell {
  width: min(1100px, 100%);
  max-width: 1120px;
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  padding: 1.5rem 1.75rem;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(2px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-logo {
  width: 64px;
}

.app-header h2 {
  font-size: 1.45rem;
  font-weight: 750;
}

.content-grid {
  display: grid;
  gap: 1.25rem;
}

.panel {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: var(--shadow);
  padding: 1.5rem;
  transition: box-shadow 0.22s ease, border-color 0.22s ease;
  position: relative;
  overflow: hidden;
}

.panel:hover {
  box-shadow: 0 12px 24px rgba(17, 24, 39, 0.08);
  border-color: #dde1e8;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, #8f0000, #b30000, #d92929);
}

.section-header {
  margin-bottom: 1rem;
}

.section-header h3 {
  font-size: 1.2rem;
  margin-top: 0.35rem;
  font-weight: 730;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.field-card {
  padding: 1rem;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid var(--border);
}

.field-card.full-width {
  grid-column: 1 / -1;
}

.field-card select,
.field-card input {
  width: 100%;
  padding: 0.9rem 1rem;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field-card select:focus,
.field-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(179, 0, 0, 0.2);
}

.field-card select:disabled,
.field-card select.store-select-disabled {
  opacity: 0.55;
  background: #f3f4f6;
  color: #6b7280;
  cursor: not-allowed;
  border-color: #e5e7eb;
}

button:disabled.btn-primary {
  opacity: 0.55;
  cursor: not-allowed;
}

.field-title {
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.2rem;
}

.filter-card {
  display: grid;
  gap: 0.6rem;
  padding: 0.9rem;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid var(--border);
}

.scanner-panel {
  margin-bottom: 1.25rem;
}

.scanner-field-row {
  display: flex;
  align-items: stretch;
  gap: 0.75rem;
}

.scanner-panel input {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 0.95rem 1rem;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.scanner-panel input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(179, 0, 0, 0.2);
}

.scanner-add-btn {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-height: 48px;
  padding: 0.95rem 1.15rem;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 900px) {
  .scanner-add-btn {
    display: inline-flex;
  }
}

@media (max-width: 640px) {
  .scanner-field-row {
    flex-direction: column;
  }

  .scanner-add-btn {
    width: 100%;
    min-height: 52px;
  }
}

.session-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
  border-radius: 20px;
  background: #fff8f8;
  border: 1px solid rgba(179, 0, 0, 0.14);
}

.session-meta {
  display: grid;
  gap: 0.35rem;
}

.session-meta strong {
  color: var(--accent);
  font-weight: 750;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 14px;
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
  max-height: min(58vh, 540px);
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

thead {
  background: #fff7f7;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff7f7;
  font-weight: 700;
  color: #374151;
}

th,
td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid #edf0f4;
  font-size: 0.95rem;
}

tbody tr:nth-child(even) {
  background: #fcfdff;
}

tbody tr:hover {
  background: #fff9f9;
}

.qty-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.qty-inline button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  color: var(--text);
  min-height: 36px;
  padding: 0;
}

.qty-inline span {
  min-width: 30px;
  text-align: center;
  font-weight: 700;
}

.warning-banner {
  border-radius: 18px;
  padding: 1rem;
  background: #fff1f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  margin-bottom: 1rem;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 39, 0.5);
  padding: 1.5rem;
  z-index: 110;
}

.modal-card {
  width: min(700px, 100%);
  padding: 1.75rem;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-strong);
  border: 1px solid var(--border);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1.5rem;
}

.setup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1.25rem;
}

.panel-nav {
  margin-bottom: 1rem;
}

.panel-nav .btn-secondary {
  min-height: 44px;
  padding: 0.65rem 1.15rem;
}

.modal-card-scroll {
  max-height: min(85vh, 720px);
  display: flex;
  flex-direction: column;
}

.menu-screen {
  max-width: 480px;
  margin: 0 auto;
}

.menu-screen-inner {
  text-align: center;
  padding: 0.5rem 0 0.25rem;
}

.menu-header h2 {
  margin-bottom: 0.35rem;
}

.menu-welcome {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 1rem;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-top: 1.75rem;
}

.menu-action-btn {
  max-width: 100%;
  width: 100%;
}

.menu-version {
  margin-top: 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: pre-line;
  line-height: 1.4;
}

.report-block {
  margin-bottom: 1rem;
}

.report-period-label {
  margin-top: 0.5rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.report-period-value {
  margin: 0.25rem 0 1rem;
  font-weight: 600;
  color: var(--text);
}

.report-generate-btn {
  margin-top: 0.25rem;
}

.report-date-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

#adminReportBackBtn {
  margin-top: 0.5rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: min(52vh, 480px);
  overflow-y: auto;
  margin-top: 0.5rem;
  padding-right: 0.25rem;
}

.history-item {
  padding: 1rem 1.1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.history-store {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  color: var(--text);
}

.history-meta {
  margin: 0.15rem 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.history-stats {
  margin: 0.5rem 0 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.45;
}

.history-empty {
  margin: 1rem 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 120;
  backdrop-filter: blur(2px);
}

.loading-content {
  padding: 1.35rem 1.8rem;
  border-radius: var(--radius);
  background: #fff;
  text-align: center;
  box-shadow: var(--shadow-strong);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 52px;
  height: 52px;
  border: 5px solid rgba(179, 0, 0, 0.16);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 1.35rem 1.75rem;
  min-width: 210px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-strong);
  animation: toastSuccessIn 0.28s ease;
  z-index: 130;
}

.toast-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  text-align: center;
}

.toast-success-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.toast-success-icon svg {
  width: 26px;
  height: 26px;
}

#successToastText {
  margin: 0;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  letter-spacing: 0.01em;
}

.logout-btn {
  padding: 0.9rem 1.4rem;
  border-radius: 12px;
  background: #fff;
  color: var(--accent);
  border: 1px solid rgba(179, 0, 0, 0.3);
  box-shadow: 0 6px 14px rgba(17, 24, 39, 0.07);
}

.end-session-btn {
  margin-top: 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastSuccessIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@media (max-width: 900px) {
  .splash-header,
  .app-header {
    text-align: center;
  }

  .brand-block {
    justify-content: center;
    text-align: center;
  }

  .field-grid,
  .filter-row {
    grid-template-columns: 1fr;
  }

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

  .logout-btn {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .splash-card,
  .auth-card,
  .panel {
    padding: 1.5rem;
  }

  .app-header {
    padding: 1.2rem;
  }

  .splash-header {
    gap: 1rem;
  }

  .screen {
    padding: 1rem;
  }

  .splash-card {
    max-width: 320px;
  }

  #splashScreen h1 {
    font-size: clamp(1.55rem, 8vw, 1.9rem);
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }

  .setup-actions {
    grid-template-columns: 1fr;
  }

  .report-date-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: 48vh;
  }

  .auth-form {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  #loginScreen .section-header h2 {
    font-size: 1.3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
