:root {
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-color: #333;
    --primary-color: #fe2c55; /* TikTok Pink/Red */
    --secondary-color: #25f4ee; /* TikTok Teal */
    --border-color: #e0e0e0;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --border-radius: 12px;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    line-height: 1.6;
    transition: background-color 0.5s ease;
}

body.login-active {
    background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    color: #fff;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 0;
    margin: 0;
    overflow: hidden; /* Prevent scrollbars from gradient background */
}

/* New Login Box Styles */
.login-box {
  background-color: rgba(0, 0, 0, 0.8);
  padding: 40px;
  border-radius: 15px;
  box-shadow: 0 0 20px #0ff;
  text-align: center;
  width: 100%;
  max-width: 400px;
  animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.login-box h2 {
  margin-bottom: 2rem;
  color: #0ff;
  text-shadow: 0 0 10px #0ff;
  font-size: 2rem;
  font-weight: 600;
}

.login-box .form-group {
    margin-bottom: 1.5rem;
}

.login-box input[type="text"],
.login-box input[type="password"] {
  width: 100%;
  padding: 12px;
  margin: 0;
  border: 1px solid #444;
  border-radius: 8px;
  background-color: #222;
  color: #fff;
  font-size: 16px;
  box-sizing: border-box;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.login-box input[type="text"]:focus,
.login-box input[type="password"]:focus {
    outline: none;
    background-color: #222;
    color: #fff;
    border-color: #0ff;
    box-shadow: 0 0 10px #0ff;
}

.login-box .btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background-color: #00ffff;
  border-color: #00ffff;
  color: #000;
  font-weight: bold;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.2s, box-shadow 0.3s;
}

.login-box .btn:hover {
  background-color: #00cccc;
  border-color: #00cccc;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 255, 255, 0.4);
}

.login-box .error {
    color: #ff4d4d;
    margin-top: 10px;
    min-height: 24px; /* prevent layout shift */
    font-weight: 400;
}

.container {
    max-width: 800px;
    margin: 0 auto;
}

header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    position: relative; /* For positioning connection status */
}

.logo {
    width: 50px;
    height: 50px;
    flex-shrink: 0;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
    flex-grow: 1;
}

/* Connection Status Indicator */
.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    position: absolute;
    top: -15px;
    right: 0;
}

.connection-status .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.connection-status.offline {
    background-color: #f8d7da;
    color: #721c24;
}
.connection-status.offline .dot {
    background-color: #dc3545;
}

.connection-status.online {
    background-color: #d4edda;
    color: #155724;
}
.connection-status.online .dot {
    background-color: #28a745;
}

h2 {
    font-weight: 600;
    color: var(--text-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 1rem;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
    text-align: left;
}

.summary-card, .form-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    animation: fadeIn 0.6s ease-out forwards;
    opacity: 0;
}

.admin-user-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

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

#total-earnings, #pending-earnings {
    font-size: 2.2rem;
    font-weight: 700;
    color: #27ae60; /* Green for net earnings */
    text-align: center;
    margin: 0;
}

#pending-earnings {
    color: var(--primary-color);
}

.summary-grid {
    display: flex;
    justify-content: space-around;
    text-align: center;
    gap: 1rem;
}

.summary-grid h4 {
    margin: 0 0 0.5rem 0;
    font-weight: 600;
    color: #555;
    font-size: 1rem;
}

.admin-earnings-card h2 {
    text-align: center;
}

.admin-earnings-card #admin-total-earnings,
.admin-earnings-card #admin-pending-earnings {
    font-size: 2.5rem;
    font-weight: 700;
    color: #27ae60;
    text-align: center;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.1);
    margin: 0;
}

.admin-earnings-card #admin-pending-earnings {
    color: var(--primary-color);
}

.error-message {
    color: var(--primary-color);
    text-align: center;
    margin-top: 1rem;
    height: 1em;
    font-weight: 300;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
}

.form-group-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 1.5rem; /* Add some space above */
}

.form-group-checkbox input[type="checkbox"] {
    width: auto;
    height: 20px; /* Make checkbox bigger */
    width: 20px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.form-group-checkbox label {
    margin-bottom: 0; /* Align label with checkbox */
    cursor: pointer;
    font-weight: normal; /* Normal weight for checkbox label */
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: 'Poppins', sans-serif;
    box-sizing: border-box;
}

.form-group select {
    background-color: #fff;
    font-size: 1rem;
}

.btn {
    display: block;
    width: 100%;
    padding: 12px;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background 0.3s;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.6s ease;
    z-index: -1;
}

.btn:hover::before {
    left: 100%;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

header nav {
    display: flex;
    gap: 10px;
}

.nav-btn {
    padding: 8px 16px;
    background: var(--text-color);
    font-size: 0.9rem;
    width: auto;
}

.nav-btn:hover {
    background: #555;
    transform: none;
    box-shadow: none;
    color: white;
}

.records-section {
    margin-top: 2rem;
}

.hidden {
    display: none !important;
}

.empty-state {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--border-radius);
    text-align: center;
    color: #888;
    box-shadow: var(--shadow);
}

/* Add a wrapper for all tables to control scrolling */
.table-wrapper {
    overflow-x: auto;
    width: 100%;
    margin-top: 1rem;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* New wrapper for history sections */
.history-wrapper {
    max-height: 60vh;
    overflow-y: auto;
    padding: 5px;
    margin-top: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--bg-color);
}

.day-record {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.day-record h3 {
    margin-top: 0;
    font-weight: 600;
    font-size: 1.4rem;
}

.day-summary {
    display: flex;
    gap: 1.5rem;
    justify-content: space-around;
    padding: 1rem;
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin: 1rem 0;
    text-align: center;
    flex-wrap: wrap;
}

.day-summary > div {
    flex: 1;
    min-width: 150px;
}

.day-summary h4 {
    margin: 0 0 5px 0;
    font-size: 0.9rem;
    color: #555;
    font-weight: 600;
    text-transform: uppercase;
}

.day-summary p {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 700;
}

.day-summary .summary-coins {
    color: var(--secondary-color);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

.day-summary .summary-earnings {
    color: #27ae60;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

.day-record table {
    width: 100%;
    border-collapse: collapse;
}

.day-record th, .day-record td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.day-record th:nth-child(2), .day-record td:nth-child(2),
.day-record th:nth-child(3), .day-record td:nth-child(3),
.day-record th:nth-child(4), .day-record td:nth-child(4) {
    text-align: right;
}

.day-record th:nth-child(5), .day-record td:nth-child(5) {
    text-align: center;
}

.day-record th {
    font-weight: 600;
}

.day-record .discount-col {
    color: #e74c3c; /* Red for discount */
    font-weight: 600;
}

.day-record .net-earnings-col {
    color: #27ae60; /* Green for net earnings */
    font-weight: 700;
}

.day-record tr:last-child td {
    border-bottom: none;
}

.delete-btn {
    background: none;
    border: 1px solid #ffcccc;
    color: var(--primary-color);
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    transition: background-color 0.2s, color 0.2s;
}

.delete-btn:hover {
    background-color: var(--primary-color);
    color: white;
}

.user-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.edit-btn {
    background: none;
    border: 1px solid #ccc;
    color: #555;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
    margin-left: 5px;
}

.edit-btn:hover {
    background-color: #f0f0f0;
    border-color: #aaa;
    color: #333;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 500px;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 2rem;
    font-size: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.modal-actions .btn {
    width: 100%;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

/* PWA Install Prompt Styles */
.pwa-modal-content {
    text-align: center;
}

.pwa-modal-content h2 {
    text-align: center;
    border-bottom: none;
    margin-bottom: 1rem;
}

.pwa-modal-icon {
    width: 80px;
    height: 80px;
    margin-bottom: 1rem;
}

/* New styles for detailed admin summary */
.admin-user-summary {
    display: flex;
    justify-content: space-around;
    background: #f9f9f9;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    text-align: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.admin-user-summary div {
    flex: 1;
    min-width: 150px;
}

.admin-user-summary p {
    margin: 0 0 5px 0;
    font-size: 0.9rem;
    color: #555;
    font-weight: 600;
    text-transform: uppercase;
}

.admin-user-summary .summary-value {
    font-size: 1.3rem;
    font-weight: 700;
}

.admin-user-summary .summary-value.net {
    color: #fff;
    background-color: #27ae60;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 1.5rem;
    display: inline-block;
}

.admin-user-summary .summary-value.admin-profit {
    color: #fff;
    background-color: var(--primary-color);
    font-weight: 700;
    font-size: 1.3rem;
    padding: 3px 8px;
    border-radius: 6px;
    display: inline-block;
}

.admin-user-summary-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    background: #f9f9f9;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.summary-detail-group {
    border-left: 3px solid var(--border-color);
    padding-left: 1rem;
}
.summary-detail-group.pending {
    border-left-color: var(--primary-color);
}
.summary-detail-group.paid {
    border-left-color: #27ae60;
}

.summary-detail-group h5 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    font-weight: 700;
}
.summary-detail-group.pending h5 { color: var(--primary-color); }
.summary-detail-group.paid h5 { color: #27ae60; }

.summary-detail-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}
.summary-detail-row span:first-child {
    color: #333;
}
.summary-detail-row span:last-child {
    font-weight: 600;
}
.summary-detail-row .net-value { color: #27ae60; font-weight: 700; }
.summary-detail-row .admin-value { color: var(--primary-color); font-weight: 700; }

.user-filter-card {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.filters-container {
    display: flex;
    gap: 1.5rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filters-container .form-group {
    flex: 1;
    min-width: 200px;
    margin-bottom: 0;
}

.date-filter-group {
    display: flex;
    gap: 0.5rem;
}

.admin-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border-color);
}

.admin-nav-btn {
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background-color: transparent;
    color: #888;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    position: relative;
    top: 2px;
}

.admin-nav-btn:hover {
    color: var(--text-color);
}

.admin-nav-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.scrollable-history {
    max-height: 50vh; /* 50% of the viewport height */
    overflow-y: auto;
    padding: 5px; /* A bit of padding so content isn't flush with edges */
    border-radius: var(--border-radius);
    background-color: var(--bg-color); /* Match body background */
}

/* This is now handled by history-wrapper */
.admin-history-list {
    /* Rules removed */
}

/* We remove padding from the inner day-record as it's now on the scroll container */
.history-wrapper .day-record {
    padding: 1.5rem;
    box-shadow: var(--shadow);
    background: var(--card-bg);
    border-radius: var(--border-radius);
    margin: 1rem;
}

.admin-history-list .paid-row {
    background-color: #ffebee; /* Light red background for paid rows */
    color: #c62828; /* Darker red text for contrast */
}

.admin-history-list .paid-row td {
    text-decoration: line-through; /* Strike through paid rows */
    text-decoration-thickness: 1.5px;
    text-decoration-color: #c62828;
}

.admin-history-list .paid-row .paid-cell,
.admin-history-list .paid-row .paid-cell * {
    text-decoration: none; /* Don't strike through the checkbox itself */
}

.paid-checkbox {
    cursor: pointer;
    transform: scale(1.2);
}

.paid-cell {
    text-align: center !important;
}

/* This is now handled by history-wrapper */
.admin-history-list .day-record {
    /* Rules removed */
}

.data-management-card {
    margin-top: 2rem;
}

.data-management-card p {
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 1.5rem;
}

.data-actions {
    display: flex;
    gap: 1rem;
}

/* New styles for payment history table */
#payment-history-container table th, #payment-history-container table td {
    text-align: right;
    vertical-align: middle;
}

#payment-history-container table th:first-child,
#payment-history-container table td:first-child {
    text-align: left; /* User column */
}

#payment-history-container table .admin-value {
    color: var(--primary-color);
    font-weight: 700;
}

/* --- Loader Styles --- */
#loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

#loader-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 5px solid var(--secondary-color);
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Toast Notification Styles --- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background-color: #333;
    color: #fff;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    min-width: 250px;
    max-width: 350px;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.success {
    background-color: #27ae60;
}

.toast.error {
    background-color: #e74c3c;
}

.toast.info {
    background-color: #3498db;
}

/* --- Responsive Design --- */
@media (max-width: 820px) {
    body {
        padding: 10px;
    }

    .container {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    header nav {
        width: 100%;
        justify-content: flex-start;
    }

    .connection-status {
        top: 5px;
        right: 5px;
        font-size: 0.8rem;
    }

    h1 {
        font-size: 1.8rem;
    }

    .filters-container {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .admin-nav {
        gap: 0;
        overflow-x: auto; /* Make nav scrollable on small screens */
        -ms-overflow-style: none;  /* IE and Edge */
        scrollbar-width: none;  /* Firefox */
    }

    .admin-nav::-webkit-scrollbar {
        display: none; /* Chrome, Safari, Opera */
    }

    .admin-nav-btn {
        flex-shrink: 0; /* Prevent buttons from shrinking */
    }

    .admin-user-summary {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .admin-user-summary div {
        text-align: left;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid #eee;
        padding-bottom: 10px;
    }

    .admin-user-summary div:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    .admin-user-summary p {
        margin-bottom: 0;
    }
    
    .data-actions {
        flex-direction: column;
    }

    .modal-content {
        width: 95%;
        padding: 1.5rem;
    }

    #pwa-install-banner {
        flex-direction: column;
        gap: 0.5rem;
        padding: 1rem;
    }

    #pwa-install-banner p {
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 500px) {
    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.3rem;
    }

    .day-record h3 {
        font-size: 1.2rem;
    }

    /* Wrap tables for horizontal scrolling - This is now handled by .table-wrapper */
    .records-section .day-record,
    #user-list-container .day-record,
    #existing-users-list,
    #daily-stats-container .day-record,
    #payment-history-container .day-record {
        padding: 1rem; /* Reduce padding on small screens */
    }

    table {
        min-width: 600px; /* Force table to be wide, activating scroll inside .table-wrapper */
        font-size: 0.9rem;
    }

    .admin-user-card h3 {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .modal-actions {
        flex-direction: column;
    }
}