:root {
  font-family: 'Segoe UI', Roboto, sans-serif;
  color: #333;
  background-color: #f4f6f8;
  --primary: #0054a6; /* Sercotec Blue */
  --primary-dark: #003d7a;
  --secondary: #e30613; /* Sercotec Red */
  --grey: #e2e8f0;
  --text-dark: #1e293b;
  --text-light: #64748b;
  --card-bg: #ffffff;
  --danger: #e30613;
  --success: #0054a6; /* Using Blue for success/buyer to match brand */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f4f6f8;
  color: var(--text-dark);
}

a {
  color: inherit;
}

.btn {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 0.65rem 1.5rem;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn:hover {
  background: var(--primary-dark);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--ghost {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(circle at top, var(--primary), var(--primary-dark));
}

.landing__container {
  padding: 1rem;
  width: min(420px, 90vw);
}

.landing__card {
  background: rgba(255, 255, 255, 0.95);
  padding: 2rem;
  border-radius: 1.25rem;
  text-align: center;
  box-shadow: 0 20px 70px rgba(15, 23, 42, 0.3);
}

.landing__actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 1.5rem 0;
}

.landing__hint {
  color: #475569;
  font-size: 0.95rem;
}

.admin {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem clamp(1rem, 5vw, 3rem);
  background: var(--primary-dark);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.admin__header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.status__led {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--danger);
  display: inline-block;
}

.status__led--online {
  background: #22c55e;
}

.admin-freeze-btn {
  font-size: 0.8rem;
  padding: 0.25rem 0.9rem;
}

.admin__layout {
  display: grid;
  gap: 1.5rem;
  padding: 2rem clamp(1rem, 5vw, 3rem) 3rem;
  grid-template-columns: 1fr;
}

.card {
  background: var(--card);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 15px 40px rgba(15, 23, 42, 0.08);
}

.card--controls {
  grid-area: controls;
  background: #ffffff;
  border: 1px solid var(--grey);
  border-top: 4px solid var(--primary);
}

.card--timer {
  grid-area: timer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-top: 4px solid var(--secondary);
}

.card--upload {
  grid-area: upload;
  border-top: 4px solid var(--text-light);
}

.card--tables {
  grid-area: tables;
  position: relative;
  border: 1px solid var(--grey);
  background: #ffffff;
}

@media (min-width: 900px) {
  .admin__layout {
    grid-template-columns: minmax(280px, 360px) minmax(320px, 1fr);
    grid-template-areas:
      'controls timer'
      'upload timer'
      'tables tables';
  }
}

.current-round {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 1rem 0;
}

.control-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.manual-round {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.manual-round select,
.timer-form input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--grey);
  border-radius: 0.65rem;
  font-size: 1rem;
}

.timer-display {
  font-size: 3rem;
  font-weight: 700;
  text-align: center;
  margin: 1rem 0;
  transition: color 0.2s ease;
}

.timer-display--danger {
  color: var(--danger);
}

.timer-phase {
  text-align: center;
  font-weight: 600;
  color: #475569;
  margin-top: -0.5rem;
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.85rem;
}

.timer-phase--round {
  color: #16a34a;
}

.timer-phase--break {
  color: #f97316;
}

.timer-phase--idle {
  color: #64748b;
}

.timer-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.upload-form input[type='file'] {
  padding: 0.75rem;
  border-radius: 0.65rem;
  border: 1px dashed var(--primary);
  background: rgba(37, 99, 235, 0.04);
}

.upload-status {
  font-size: 0.9rem;
  color: #475569;
  min-height: 1.2rem;
}

.upload-status.error {
  color: var(--danger);
}

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

.tables-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.assign-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 1rem;
  align-items: start;
}

.assign-layout__pools {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.pool-column {
  border: 1px solid #e2e8f0;
  border-radius: 0.9rem;
  padding: 0.9rem;
  background: #f8fafc;
}

.pool-column__title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.pool-column h3 {
  margin: 0;
  font-size: 1.05rem;
}

.pool-hint {
  font-size: 0.85rem;
  color: #94a3b8;
}

.pool-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 120px;
}

.pool-item {
  border: 1px dashed #cbd5e1;
  border-radius: 0.8rem;
  padding: 0.65rem 0.75rem;
  background: #fff;
  cursor: grab;
  transition: box-shadow 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

.pool-column--buyer .pool-item {
  border-color: rgba(22, 163, 74, 0.6);
  background: #ecfdf3;
}

.pool-column--seller .pool-item {
  border-color: rgba(234, 88, 12, 0.65);
  background: #fff7ed;
}

.pool-column--buyer .pool-item__name {
  color: #166534;
}

.pool-column--seller .pool-item__name {
  color: #9a3412;
}

.pool-column--buyer .pool-item {
  border-color: rgba(34, 197, 94, 0.5);
}

.pool-column--seller .pool-item {
  border-color: rgba(249, 115, 22, 0.6);
}

.pool-column--buyer .pool-column__title h3 {
  color: #166534;
}

.pool-column--seller .pool-column__title h3 {
  color: #c2410c;
}

.pool-item:active {
  cursor: grabbing;
}

.pool-item:hover {
  border-color: var(--primary);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
}

.pool-item__name {
  display: block;
  font-weight: 700;
  color: #0f172a;
}

.pool-item__org {
  display: block;
  font-size: 0.9rem;
  color: #475569;
}

.pool-empty {
  margin: 0;
  color: #94a3b8;
  font-size: 0.95rem;
}

.tables-header__right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tables-editor-round {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.tables-editor-round__label {
  font-size: 0.8rem;
  color: #64748b;
}

.tables-editor-round__controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tables-editor-round__controls select {
  min-width: 180px;
  padding: 0.35rem 0.6rem;
  border-radius: 0.6rem;
  border: 1px solid #e2e8f0;
  font-size: 0.9rem;
}

.tables-editor-round__button {
  font-size: 0.8rem;
  padding: 0.3rem 0.9rem;
}

.tables-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: #64748b;
}

.tables-helper {
  margin: 0 0 0.9rem;
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  color: #0f172a;
  background: #fefce8;
  border-radius: 0.75rem;
  border: 1px solid #facc15;
  font-weight: 500;
}

.validation-errors {
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: #b91c1c;
}

.validation-errors p {
  margin: 0.15rem 0;
}

.save-status {
  font-size: 0.9rem;
  color: #94a3b8;
}

.save-status--dirty {
  color: #f97316;
  font-weight: 600;
}

.pill {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary-dark);
  padding: 0.2rem 0.8rem;
  border-radius: 999px;
  font-weight: 600;
}

.pill--muted {
  background: #e2e8f0;
  color: #0f172a;
}

.toast {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  padding: 0.75rem 1.2rem;
  border-radius: 999px;
  background: #0f172a;
  color: #e5e7eb;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.35);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 30;
}

.toast--visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.tables-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 768px) {
  .tables-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1200px) {
  .tables-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.table-card {
  border: 1px solid #0f172a;
  border-radius: 1rem;
  padding: 1.3rem 1.4rem;
  background: radial-gradient(circle at 0 0, #dbeafe 0, #ffffff 55%);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
}

.table-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.table-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  color: #0f172a;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.table-card .table-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  background: rgba(15, 23, 42, 0.02);
}

.table-card .table-row:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.table-card .label {
  font-size: 0.7rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.table-card .value {
  font-weight: 600;
  color: #0f172a;
}

.table-row--draggable {
  cursor: grab;
  border-radius: 0.75rem;
  padding: 0.35rem 0.5rem;
  transition: background 0.15s ease, transform 0.1s ease;
}

.table-row--dragging {
  opacity: 0.6;
  cursor: grabbing;
}

.table-row--over {
  outline: 2px dashed var(--primary);
  background: rgba(37, 99, 235, 0.06);
}

.table-row__clear {
  align-self: flex-start;
  margin-left: auto;
  margin-top: 0.25rem;
  border: none;
  background: transparent;
  color: #ef4444;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  padding: 0;
}

.table-row__clear:hover {
  color: #b91c1c;
}

.table-row--buyer {
  border-left: 3px solid #22c55e;
  background: linear-gradient(90deg, rgba(22, 163, 74, 0.08), transparent);
}

.table-row--seller {
  border-left: 3px solid #f97316;
  background: linear-gradient(90deg, rgba(249, 115, 22, 0.08), transparent);
}

.table-row--buyer .value__primary {
  color: #166534;
}

.table-row--seller .value__primary {
  color: #9a3412;
}

.value--stacked {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.value__primary {
  font-weight: 700;
}

.value__secondary {
  font-size: 0.9rem;
  color: #475569;
}

.tv {
  background: #f8f9fa;
  min-height: 100vh;
  color: var(--text-dark);
  margin: 0;
  font-family: 'Montserrat', 'Segoe UI', sans-serif;
  position: relative;
  overflow-x: hidden;
}

.tv__bg-pattern {
  position: fixed;
  inset: 0;
  background-image: 
    radial-gradient(circle at 10% 10%, rgba(0, 84, 166, 0.03) 0%, transparent 40%),
    radial-gradient(circle at 90% 90%, rgba(227, 6, 19, 0.03) 0%, transparent 40%);
  opacity: 1;
  pointer-events: none;
  z-index: 0;
}

.tv__wrapper {
  padding: 1.5rem 2rem;
  position: relative;
  z-index: 1;
  max-width: 98vw;
  margin: 0 auto;
}

.tv__dashboard-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: #ffffff;
  padding: 0.8rem 2rem;
  border-radius: 1rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 1.5rem;
  border-top: 6px solid var(--primary);
  gap: 2rem;
}

.tv__brand-area {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  justify-self: start;
}

.tv__logo {
  height: 110px;
  width: auto;
  object-fit: contain;
}

.tv__title-group {
  display: flex;
  flex-direction: column;
}

.tv__title-group h2 {
  margin: 0;
  font-size: 2rem;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 800;
  line-height: 1.1;
}

.tv__title-group h3 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text-light);
  font-weight: 600;
}

.tv__round-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f1f5f9;
  padding: 0.5rem 1.5rem;
  border-radius: 0.8rem;
  border: 1px solid var(--grey);
  justify-self: end;
  min-width: 140px;
}

.tv__label-mini {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-light);
  font-weight: 700;
}

.tv__round-number {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1;
}

.tv__timer-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--primary);
  padding: 0.5rem 4rem;
  border-radius: 1rem;
  color: white;
  box-shadow: 0 4px 25px rgba(0, 84, 166, 0.4);
  min-width: 320px;
  position: relative;
  overflow: hidden;
  justify-self: center;
  transform: scale(1.3);
  z-index: 10;
}

.tv__timer-display::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(to bottom, rgba(255,255,255,0.1), transparent);
  pointer-events: none;
}

.tv__timer-display.tv__timer--danger {
  background: var(--danger);
  animation: pulse-danger 1.5s infinite;
}

.tv__timer-display.tv__timer--break {
  background: #f97316; /* Orange for break */
}

.tv__timer-value {
  font-family: 'Courier New', monospace;
  font-size: 4.5rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.05em;
}

.tv__phase-badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.2rem 0.8rem;
  border-radius: 999px;
  margin-top: 0.2rem;
}

/* Grid adjustments for better visibility */
.tv__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.tv-card {
  background: #ffffff;
  border-radius: 0.8rem;
  padding: 0; /* Remove padding to use full space */
  border: 1px solid var(--grey);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 130px;
}

.tv-card__heading {
  background: #f8fafc;
  padding: 0.4rem 1rem;
  border-bottom: 1px solid var(--grey);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tv-card h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--primary-dark);
  font-weight: 800;
  border: none;
  padding: 0;
}

.tv-card__companies {
  display: flex;
  flex: 1;
  flex-direction: column; /* Stack vertically for better name visibility */
}

.tv-card .company {
  flex: 1;
  padding: 0.6rem 1rem;
  border-radius: 0;
  background: white;
  border-left: 6px solid transparent;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.tv-card .company--buyer {
  border-left-color: var(--primary);
  border-bottom: 1px solid #f1f5f9;
}

.tv-card .company--seller {
  border-left-color: var(--danger);
}

.company__name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.2;
}

.company__org {
  font-size: 0.95rem;
  color: var(--text-light);
  font-weight: 500;
}

@media (min-width: 1400px) {
  .company__name {
    font-size: 1.5rem;
  }
  .company__org {
    font-size: 1.1rem;
  }
  .tv-card h3 {
    font-size: 1.2rem;
  }
  .tv__timer-value {
    font-size: 6rem;
  }
  .tv__round-number {
    font-size: 3.5rem;
  }
}

.tv-card .vs {
  text-transform: uppercase;
  font-size: 0.95rem;
  letter-spacing: 0.4em;
  color: #94a3b8;
  text-align: center;
  align-self: center;
  padding: 0 0.5rem;
}

.tv__scroll-hint {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  color: #e5e7eb;
}

.tv__scroll-hint--visible {
  opacity: 1;
}

.tv__scroll-arrow {
  animation: bounce 1.2s infinite;
  display: inline-block;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(3px);
  }
}

/* Responsive Adjustments */

@media (max-width: 1024px) {
  .tv__dashboard-header {
    grid-template-columns: 1fr auto;
    gap: 1rem;
  }
  
  .tv__brand-area {
    grid-column: 1 / -1;
    justify-content: center;
    margin-bottom: 1rem;
  }
  
  .tv__timer-display {
    grid-column: 1 / 2;
    transform: scale(1);
    min-width: auto;
    width: 100%;
  }
  
  .tv__round-display {
    grid-column: 2 / 3;
    min-width: auto;
  }
}

@media (max-width: 768px) {
  /* Admin Adjustments */
  .admin__header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    padding: 1rem;
  }

  .admin__header > div:first-child {
    justify-content: center;
    width: 100%;
  }

  .admin__header-right {
    align-items: center;
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
  }

  .manual-round {
    flex-direction: column;
    align-items: stretch;
  }

  .assign-layout {
    grid-template-columns: 1fr;
  }

  .tables-grid {
    grid-template-columns: 1fr;
  }

  /* TV Adjustments */
  .tv__dashboard-header {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 1rem;
  }

  .tv__brand-area {
    flex-direction: column;
    text-align: center;
    gap: 0.5rem;
  }

  .tv__logo {
    height: 60px;
  }

  .tv__title-group h2 {
    font-size: 1.5rem;
  }

  .tv__title-group h3 {
    font-size: 1rem;
  }

  .tv__timer-display {
    transform: none;
    width: 100%;
    min-width: 0;
    padding: 1rem;
  }

  .tv__timer-value {
    font-size: 3.5rem;
  }

  .tv__round-display {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
  }
  
  .tv__round-number {
    font-size: 2rem;
  }

  .tv__wrapper {
    padding: 0.5rem;
  }
  
  .tv-card {
    min-height: auto;
  }
  
  .company__name {
    font-size: 1.1rem;
  }
}

@media (max-width: 480px) {
  .landing__container {
    width: 100%;
    padding: 1rem;
  }

  .control-buttons {
    flex-direction: column;
  }
  
  .control-buttons .btn {
    width: 100%;
  }

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

  .tables-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }
  
  .tables-header__right {
    flex-direction: column;
    align-items: stretch;
  }
  
  .tables-header__right .btn {
    width: 100%;
  }
  
  .pool-column {
    padding: 0.5rem;
  }

  .toast {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    text-align: center;
  }
}
