/* =====================================================================
   Tax Submission Tracker — ported 1:1 from the Google Apps Script UI
   (GoogleAppsScript/index.html). Keep visual parity with the original.
   ===================================================================== */

:root {
  --sidebar-width: 250px;
  --sidebar-collapsed-width: 70px;
  --primary-color: #2c3e50;
  --secondary-color: #34495e;
  --accent-color: #3498db;
  --light-bg: #f8f9fa;
  --success-color: #27ae60;
  --warning-color: #f39c12;
  --clean-color: #1abc9c;

  /* Sidebar palette — a deeper navy than the flat #2c3e50 of the original,
     lit by a teal and a blue glow so the panel reads with some depth.
     Colours only: every size, spacing, and animation is unchanged. */
  --sidebar-top: #1b3048;
  --sidebar-mid: #16273c;
  --sidebar-bottom: #101d2e;
  --sidebar-accent: #24d3b0;
  --sidebar-text: rgba(232, 240, 247, 0.82);
}

body {
  font-family: 'Sarabun', sans-serif;
  transition: margin-left 0.3s ease;
}

body.login-page {
  /* Same layered treatment as the sidebar so the two read as one product:
     dot texture, a teal and a blue glow, then the deep navy base. */
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.05) 1px, transparent 1px) 0 0 / 26px 26px,
    radial-gradient(60% 55% at 15% 10%, rgba(36, 211, 176, 0.24), transparent 65%),
    radial-gradient(55% 55% at 88% 88%, rgba(52, 152, 219, 0.24), transparent 62%),
    linear-gradient(150deg, var(--sidebar-top) 0%, var(--sidebar-mid) 50%, var(--sidebar-bottom) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

body.app-page {
  background-color: #f5f7f9;
  min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Kanit', sans-serif;
}

/* ---------------------------------------------------------------- Login */
.login-container {
  background: #fff;
  border-radius: 20px;
  /* A deep ambient shadow plus a faint teal halo lifts the card off the
     dark background instead of leaving it flat. */
  box-shadow:
    0 30px 70px rgba(6, 12, 22, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 90px -30px rgba(36, 211, 176, 0.55);
  overflow: hidden;
  max-width: 420px;
  width: 100%;
  animation: slideInUp 0.6s ease;
}

.login-header {
  background:
    radial-gradient(90% 120% at 15% 0%, rgba(255, 255, 255, 0.22), transparent 60%),
    linear-gradient(135deg, var(--sidebar-accent) 0%, #17a5c9 55%, var(--accent-color) 100%);
  color: white;
  padding: 2.5rem 2rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.25);
}

.login-header::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.16) 1px, transparent 1px);
  background-size: 20px 20px;
  animation: float 6s ease-in-out infinite;
}

.login-header h3 {
  position: relative;
  margin: 0;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.28);
}

.login-body {
  padding: 2.5rem 2rem;
}

.form-control {
  border-radius: 12px;
  padding: 14px 16px;
  border: 2px solid #e6eaf0;
  transition: all 0.3s ease;
  font-size: 0.95em;
}

.form-control:focus {
  border-color: var(--sidebar-accent);
  box-shadow: 0 0 0 0.2rem rgba(36, 211, 176, 0.22);
  transform: translateY(-2px);
}

.login-page .form-label {
  color: #33465c;
  font-weight: 500;
}

.btn-login {
  background: linear-gradient(135deg, var(--sidebar-accent) 0%, #10a888 100%);
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-weight: 500;
  color: white;
  transition: all 0.3s ease;
  font-size: 1em;
  box-shadow: 0 10px 24px -12px rgba(36, 211, 176, 0.95);
}

.btn-login:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px -10px rgba(36, 211, 176, 0.75);
  color: white;
}

.password-toggle {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #6c757d;
  cursor: pointer;
  transition: color 0.3s ease;
  z-index: 5;
}

.password-toggle:hover {
  color: var(--clean-color);
}

.password-container {
  position: relative;
}

/* -------------------------------------------------------------- Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  position: fixed;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  z-index: 1000;
  transition: all 0.3s ease;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  /* Layered background: a fine dot texture (the same motif as the login
     header), two coloured glows, then the base gradient. */
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 22px 22px,
    radial-gradient(120% 45% at 0% 0%, rgba(36, 211, 176, 0.20), transparent 62%),
    radial-gradient(100% 45% at 100% 100%, rgba(52, 152, 219, 0.16), transparent 60%),
    linear-gradient(165deg, var(--sidebar-top) 0%, var(--sidebar-mid) 52%, var(--sidebar-bottom) 100%);
  box-shadow:
    6px 0 28px rgba(8, 15, 26, 0.45),
    inset -1px 0 0 rgba(255, 255, 255, 0.06);
}

/* Slim, unobtrusive scrollbar so it does not break the dark panel. */
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 3px;
}
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(36, 211, 176, 0.45); }

.sidebar-title {
  color: #fff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

.sidebar-title i {
  color: var(--sidebar-accent);
  filter: drop-shadow(0 0 9px rgba(36, 211, 176, 0.55));
}

.sidebar-collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar-content {
  transition: all 0.3s ease;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.sidebar-main {
  flex: 1;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  /* A hairline that fades out at both ends instead of a hard rule. */
  border-top: 1px solid transparent;
  border-image: linear-gradient(90deg,
      transparent, rgba(255, 255, 255, 0.18) 25%, rgba(36, 211, 176, 0.35) 55%, transparent) 1;
}

.sidebar-footer .text-white-50 { color: rgba(36, 211, 176, 0.75) !important; }

.sidebar-collapsed .sidebar-title,
.sidebar-collapsed .nav-link span {
  display: none;
}

.sidebar-collapsed .nav-link {
  justify-content: center;
  padding: 12px 8px;
  margin-bottom: 5px;
}

.sidebar-collapsed .nav-link i {
  margin-right: 0;
  font-size: 1.3rem;
}

.main-content {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  transition: margin-left 0.3s ease, width 0.3s ease;
}

.sidebar-collapsed ~ .main-content {
  margin-left: var(--sidebar-collapsed-width);
  width: calc(100% - var(--sidebar-collapsed-width));
}

/* ------------------------------------------------------------- Nav link */
.sidebar .nav-link {
  border-radius: 0.375rem;
  margin-bottom: 0.25rem;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  padding: 12px 15px;
  color: var(--sidebar-text);
  text-decoration: none;
  cursor: pointer;
  border-left: 4px solid transparent;
}

.sidebar .nav-link:hover {
  background: linear-gradient(90deg,
      rgba(36, 211, 176, 0.22) 0%, rgba(36, 211, 176, 0.05) 55%, transparent 100%);
  transform: translateX(5px);
  color: #fff;
  border-left-color: var(--sidebar-accent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 8px 20px -12px rgba(0, 0, 0, 0.8);
}

.sidebar .nav-link.active {
  background: linear-gradient(90deg,
      rgba(36, 211, 176, 0.30) 0%, rgba(36, 211, 176, 0.08) 60%, transparent 100%);
  color: #fff;
  border-left-color: var(--sidebar-accent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.10),
    0 10px 24px -14px rgba(36, 211, 176, 0.9);
}

.sidebar .nav-link i {
  margin-right: 12px;
  font-size: 1.2rem;
  min-width: 24px;
  text-align: center;
  transition: margin-right 0.3s ease, color 0.3s ease;
  color: rgba(255, 255, 255, 0.55);
}

.sidebar .nav-link:hover i,
.sidebar .nav-link.active i {
  color: var(--sidebar-accent);
}

.sidebar .nav-link.active i {
  filter: drop-shadow(0 0 7px rgba(36, 211, 176, 0.6));
}

/* The logout button also carries .nav-link, so these need to outrank the
   teal hover above — hence the extra .sidebar in the selector. */
.sidebar .sidebar-footer .btn-danger {
  background: linear-gradient(135deg, #e8596a 0%, #c0392b 100%);
  border: none;
  color: #fff;
  box-shadow: 0 8px 20px -12px rgba(232, 89, 106, 0.95);
}

.sidebar .sidebar-footer .btn-danger:hover {
  background: linear-gradient(135deg, #f06a7a 0%, #d0422f 100%);
  color: #fff;
  border-left-color: transparent;
  box-shadow: 0 10px 26px -12px rgba(232, 89, 106, 1);
}

.sidebar .sidebar-footer .btn-danger i,
.sidebar .sidebar-footer .btn-danger:hover i {
  color: #fff;
}

.sidebar-collapsed .nav-link i {
  margin-right: 0;
}

.table-responsive {
  overflow-x: auto;
}

.card {
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  border: none;
  transition: transform 0.3s ease;
}

.card:hover {
  transform: translateY(-5px);
}

.btn {
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.btn-primary {
  background: linear-gradient(45deg, var(--accent-color), #2980b9);
  border: none;
}

.btn-primary:hover {
  background: linear-gradient(45deg, #2980b9, var(--accent-color));
  transform: translateY(-2px);
}

.modal-content {
  border-radius: 12px;
  border: none;
}

/* Several dialogs wrap header/body/footer in a <form>, which makes the form
   the only flex item of .modal-content. Without passing the column layout
   down, .modal-body cannot shrink and the footer buttons are pushed off the
   bottom of the screen on a short window. */
.modal-content > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

/* Keep the scroll on the body, not the whole dialog. */
.modal-dialog-scrollable .modal-content > form > .modal-body {
  overflow-y: auto;
  min-height: 0;
}

.modal-header {
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  background: linear-gradient(135deg, var(--primary-color) 0%, #2c3e50 100%);
  color: white;
}

.form-control, .form-select, .bootstrap-select .btn {
  border-radius: 6px;
  padding: 10px 15px;
}

.bootstrap-select .dropdown-menu {
  border-radius: 6px;
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.spinner-border {
  width: 3rem;
  height: 3rem;
}

.user-info {
  transition: all 0.3s ease;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  padding: 15px;
  margin-bottom: 15px;
}

.user-info:hover {
  background: rgba(255, 255, 255, 0.2) !important;
}

/* --------------------------------------------------------------- Mobile */
.menu-toggle {
  display: none;
  position: fixed;
  top: 15px;
  left: 15px;
  z-index: 1001;
  background: linear-gradient(135deg, var(--sidebar-top), var(--sidebar-bottom));
  color: white;
  border: none;
  border-radius: 5px;
  padding: 8px 12px;
  font-size: 1.2rem;
  box-shadow: 0 6px 18px rgba(8, 15, 26, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

/* Tooltip for the collapsed sidebar */
.sidebar-collapsed .nav-link {
  position: relative;
}

.sidebar-collapsed .nav-link::after {
  content: attr(data-title);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(135deg, var(--sidebar-top), var(--sidebar-bottom));
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.875rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 1001;
  margin-left: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(36, 211, 176, 0.25);
}

.sidebar-collapsed .nav-link:hover::after {
  opacity: 1;
  visibility: visible;
}

.top-navbar {
  background: white;
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 999;
}

.content-area {
  padding: 2rem;
}

/* ----------------------------------------------------------- Animations */
@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(1deg); }
}

@keyframes slideInUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

/* -------------------------------------------------------------- Submenu */
#reportsSubmenu .nav-link,
#keyinSubmenu .nav-link {
  padding: 8px 15px 8px 35px;
  font-size: 0.9em;
  border-left: 3px solid transparent;
}

#reportsSubmenu .nav-link:hover,
#reportsSubmenu .nav-link.active,
#keyinSubmenu .nav-link:hover,
#keyinSubmenu .nav-link.active {
  border-left-color: var(--sidebar-accent);
  background: linear-gradient(90deg,
      rgba(36, 211, 176, 0.16) 0%, rgba(36, 211, 176, 0.03) 70%, transparent 100%);
  box-shadow: none;
}

.sidebar-collapsed #reportsSubmenu,
.sidebar-collapsed #keyinSubmenu {
  display: none !important;
}

.sidebar-collapsed .nav-link[data-bs-target="#reportsSubmenu"] span,
.sidebar-collapsed .nav-link[data-bs-target="#reportsSubmenu"] .toggle-icon,
.sidebar-collapsed .nav-link[data-bs-target="#keyinSubmenu"] span,
.sidebar-collapsed .nav-link[data-bs-target="#keyinSubmenu"] .toggle-icon {
  display: none;
}

.toggle-icon {
  font-size: 0.7em;
  transition: transform 0.3s;
}

/* ------------------------------------------------------ Data table look */
/* Matches the tables the GAS pages rendered client-side. */
.data-table {
  font-size: 0.9rem;
}

.data-table thead th {
  vertical-align: middle;
  text-align: center;
}

.data-table tr.table-summary td {
  background: #fff3cd !important;
  font-weight: 700;
}

/* "ปรับขนาดการแสดงผล" shrinks a wide table with a CSS transform. A transform
   does not shrink the layout box, and the box is widened to 100/scale% so the
   scaled content still fills the card — so it must be clipped here, otherwise
   the whole page scrolls sideways and slides under the fixed sidebar. */
.scale-viewport {
  /* Hidden, not auto: the widened box overflows this frame on paper, but the
     transform pulls the visible content back inside it, so a scrollbar here
     would only scroll across blank space. Real sideways scrolling still
     happens in the .table-responsive inside. */
  overflow: hidden;
  max-width: 100%;
}

.scale-wrapper {
  transform-origin: top left;
  display: block;
}

.status-รอตรวจสอบ, .status-รอจ่ายเงิน { color: #dc3545; }
.status-ตรวจสอบแล้ว { color: #0d6efd; }
.status-จ่ายแล้ว { color: #198754; }

/* ------------------------------------------------------------ Export page */
.sheet-card {
  transition: all 0.3s ease;
  cursor: pointer;
}

.sheet-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.sheet-card.selected {
  border: 1px solid #0d6efd;
  background-color: rgba(13, 110, 253, 0.05);
}

.checkbox-wrapper input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

/* ------------------------------------------------------------- Keyin view */
.company-header {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  border-radius: 6px;
}

.wtype-header td {
  background-color: #f5a623 !important;
  color: white !important;
  font-weight: bold;
  font-size: 1.1em;
}

.status-badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75em;
  font-weight: 500;
  display: inline-block;
  min-width: 70px;
  text-align: center;
}

.status-done { background-color: #28a745; color: white; }
.status-pending { background-color: #dc3545; color: white; }
.status-working { background-color: #ffc107; color: #000; }
.status-new { background-color: #17a2b8; color: white; }
.status-follow { background-color: #66b3ff; color: #000; }
.status-none { background-color: #6c757d; color: white; }

tr.row-done td { background-color: #d4edda; }
tr.row-pending td { background-color: #f8d7da; }
tr.row-working td { background-color: #fff3cd; }
tr.row-new td { background-color: #cce5ff; }
tr.row-follow td { background-color: #b8f3ff; }

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: #6c757d;
}

.empty-state i { font-size: 3rem; opacity: .55; }

/* Locked (verified) rows may not be edited by non-admins. */
.btn-locked {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ------------------------------------------------------------ Responsive */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-width); }
  .sidebar-collapsed { transform: translateX(-100%); width: var(--sidebar-width); }
  .main-content { margin-left: 0; width: 100%; }
  .sidebar-collapsed ~ .main-content { margin-left: 0; width: 100%; }
  .menu-toggle { display: block; }
  .sidebar.show { transform: translateX(0); }
  .overlay.show { display: block; }
  .sidebar-collapsed .nav-link span { display: inline; }
  .sidebar-collapsed .nav-link { justify-content: flex-start; padding: 12px 15px; }
  .sidebar-collapsed .nav-link i { margin-right: 12px; }
  .content-area { padding: 1rem; }
  .top-navbar { padding: 1rem; }
}

@media (max-width: 575.98px) {
  .login-container { margin: 1rem; max-width: none; }
  .login-header { padding: 2rem 1.5rem; }
  .login-body { padding: 2rem 1.5rem; }
  .content-area { padding: 0.75rem; }
}

/* ---------------------------------------------------------------- Print */
@page {
  size: A4 landscape;
  margin: 10mm;
}

@media print {
  body {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    background: #fff !important;
  }

  .sidebar, .menu-toggle, .overlay, .no-print, .toast-container { display: none !important; }
  .main-content { margin-left: 0 !important; width: 100% !important; }
  .content-area { padding: 0 !important; }
  .card { box-shadow: none !important; }

  /* On-screen zoom must not affect the printout, and the full table has to
     print rather than being cut off at the edge of its scroll box. */
  .scale-viewport { overflow: visible !important; height: auto !important; }
  .scale-wrapper { transform: none !important; width: 100% !important; }
  .table-responsive { overflow: visible !important; }

  table {
    font-size: 12px;
    border-collapse: collapse !important;
    width: 100% !important;
  }

  table, th, td {
    border: 1px solid #000 !important;
    padding: 6px !important;
  }

  th { text-align: center; }
  td { text-align: start; }
  .text-end { text-align: right !important; }

  th.no-print, td.no-print { display: none !important; border: none !important; }

  thead.table-primary th { background-color: #cfe2ff !important; }
  tbody tr:nth-child(even) { background-color: #f8f9fa !important; }
}
