@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');

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

body {
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(to bottom right, #808080, #40e0d0, #ffa500);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 2rem;
    background-attachment: fixed;
}

.container {
    width: 100%;
    max-width: 1200px;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px); /* For Safari */
    border-radius: 20px;
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
}

/* --- Header Layout --- */
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    position: relative;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#settings-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.3s;
}

#settings-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

#settings-btn img {
    width: 24px;
    height: 24px;
    filter: invert(1);
}

/* WebSocket Connection Status */
#connection-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    transition: all 0.3s ease-in-out;
}

#connection-status.connected {
    background-color: #2ecc71;
    box-shadow: 0 0 5px #2ecc71;
}

#connection-status.disconnected {
    background-color: #e74c3c;
    box-shadow: 0 0 5px #e74c3c;
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

.user-selection {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.user-selection button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 0.8rem 1.5rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1rem;
}

.user-selection button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.user-selection button.active {
    background: #fff;
    color: #1a1a1a;
    font-weight: 600;
}

.view {
    display: none;
}

.view.active-view {
    display: block;
}

h2 {
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.table-container {
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

td:first-child {
    width: 40px;
}

th {
    font-weight: 600;
}

tbody tr:last-child td {
    border-bottom: none;
}

tfoot td {
    font-weight: 600;
    font-size: 1.1rem;
}

.actions-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.actions-icon {
    width: 20px;
    height: 20px;
    filter: invert(1);
}

.add-item-form {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.add-item-form input, .add-item-form select {
    flex: 1;
    min-width: 150px;
    padding: 0.8rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
    font-size: 1rem;
}

.add-item-form button {
    padding: 0.8rem 1.5rem;
    border-radius: 10px;
    border: none;
    background: #fff;
    color: #1a1a1a;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.add-item-form button:hover {
    background: #ddd;
}

/* --- Summary Section --- */
.summary-section {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.2);
    min-width: 200px;
}

.summary-item strong {
    font-size: 1.5rem;
    font-weight: 600;
}

.summary-item.remaining strong.positive {
    color: #4ade80;
}

.summary-item.remaining strong.negative {
    color: #f87171;
}

.user-summary-section {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.user-summary-section input {
    width: 100%;
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 1.2rem;
    text-align: center;
    font-weight: 600;
}

/* --- Modals & Overlays --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
    transition: opacity 0.3s ease-in-out;
}

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

.modal-content, .login-content, .connection-lost-content {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 20px;
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    width: 90%;
    max-width: 450px;
    text-align: center;
}

.login-content h2, .modal-content h2 {
    margin-bottom: 1.5rem;
}

.login-content input, .admin-add-user input {
    width: 100%;
    padding: 0.8rem;
    margin-bottom: 1rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
    font-size: 1rem;
}

#login-btn, #admin-save-user-btn {
    width: 100%;
    padding: 0.8rem;
    border-radius: 10px;
    border: none;
    background: #4ade80;
    color: #1a1a1a;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

#logout-btn {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

#logout-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.settings-section {
    margin-bottom: 1.5rem;
    text-align: left;
}

.settings-section h3 {
    font-size: 1.1rem;
    margin-bottom: 0.8rem;
    color: #ddd;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.3rem;
}

.settings-divider {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    margin: 1.5rem 0;
}

.account-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.account-buttons button {
    width: 100%;
    padding: 0.8rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.account-buttons button:hover {
    background: rgba(255, 255, 255, 0.15);
}

#settings-add-user-btn {
    width: 100%;
    padding: 0.8rem;
    border-radius: 10px;
    border: none;
    background: #4a90e2;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.5rem;
}

.settings-save-btn {
    background: #4ade80 !important;
    color: #1a1a1a !important;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    border: none;
    font-weight: 600;
    cursor: pointer;
}

#admin-cancel-edit-btn {
    margin-top: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    width: 100%;
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
}

.error {
    color: #f87171;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.hidden {
    display: none !important;
}

#admin-user-list {
    margin: 1.5rem 0;
    max-height: 200px;
    overflow-y: auto;
    text-align: left;
}

.admin-user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-user-item:last-child {
    border-bottom: none;
}

.admin-user-info {
    display: flex;
    flex-direction: column;
}

.admin-user-info span {
    font-size: 0.8rem;
    color: #aaa;
}

.admin-delete-user-btn {
    background: #ff6b6b;
    border: none;
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 5px;
    cursor: pointer;
}

#settings-modal-content {
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

#settings-user-list {
    margin: 1.5rem 0;
    overflow-y: auto;
    text-align: left;
}

.settings-user-item {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.8rem;
    border-radius: 10px;
}

.settings-user-item input {
    flex: 1;
    padding: 0.5rem;
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

.modal-buttons button, .settings-delete-btn {
    padding: 0.8rem 1.5rem;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

#edit-modal-save-btn, #actions-modal-edit-btn, #settings-add-user-btn {
    background: #4a90e2;
    color: #fff;
}

#settings-add-user-btn {
    background: #4ade80;
    color: #1a1a1a;
}

#actions-modal-delete-btn, .settings-delete-btn {
    background: #ff6b6b;
    color: #fff;
}

#edit-modal-cancel-btn, #actions-modal-cancel-btn, #settings-close-btn {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}


/* --- Connection Lost --- */
.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 4px solid #fff;
    animation: spin 1s linear infinite;
}

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

/* --- Responsive Design --- */
@media (max-width: 768px) {
    body { padding: 1rem; }
    .container { padding: 1.5rem; }
    header h1 { font-size: 2rem; }
    .header-top { flex-direction: column; gap: 1rem; }
    .user-selection { flex-direction: column; }
    .add-item-form { flex-direction: column; }
    .add-item-form input, .add-item-form button, .add-item-form select { width: 100%; }
}
