/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #ff6b6b 0%, #ffa726 100%);
    min-height: 100vh;
    /* Default padding will be managed by JS based on view */
}

/* Login screen */
#loginScreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #ff6b6b 0%, #ffa726 100%);
}

.login-box {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    text-align: center;
    width: 100%;
    max-width: 400px;
}

.login-box h2 {
    margin-bottom: 1.5rem;
    color: #333;
    font-weight: 300;
}

.login-box p {
    margin-bottom: 1rem;
    color: #555;
}

.login-box .identifier-format {
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    color: #777;
}

.login-box input[type="text"] {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.login-box input[type="text"]:focus {
    outline: none;
    border-color: #ff6b6b;
}

#loginError {
    color: #ef5350;
    margin-top: 1rem;
    min-height: 1.2em;
    font-size: 0.9rem;
}

/* Main container */
#mainAppContainer {
    display: none; /* Initially hidden */
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-top: 20px;
    margin-bottom: 20px;
}

.container { /* Still used by .loading logic */
}

/* Header */
.header {
    background: linear-gradient(135deg, #26c6da 0%, #00acc1 100%);
    color: white;
    padding: 2rem;
    text-align: center;
    position: relative;
}

.header-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    flex-grow: 1;
    text-align: left;
    margin-bottom: 0;
}

.header p {
    opacity: 0.9;
    font-size: 1.1rem;
    text-align: center;
    margin-top: 0.5rem;
}

.user-info-logout {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: 1rem;
}

#currentUserIdentifier {
    font-size: 0.9rem;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    color: white;
}

.connection-status {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
}

.status-connected {
    background: rgba(102, 187, 106, 0.9);
    color: white;
}

.status-connecting {
    background: rgba(255, 193, 7, 0.9);
    color: #212529;
}

.status-error {
    background: rgba(239, 83, 80, 0.9);
    color: white;
}

/* Dropdown Menu */
.user-actions-menu {
    position: relative;
    display: inline-block;
}

#userActionsMenuButton .dropdown-arrow {
    font-size: 0.8em;
    margin-left: 5px;
    transition: transform 0.2s ease-in-out;
}

#userActionsMenuButton.open .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu-content {
    display: none; /* Hidden by default */
    position: absolute;
    right: 0;
    background-color: white;
    min-width: 200px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    border-radius: 8px;
    z-index: 100; /* Ensure it's above other content */
    margin-top: 5px;
    border: 1px solid #eee;
    overflow: hidden; /* To ensure border-radius clips children */
}

.dropdown-menu-content.show { /* Class to display the dropdown */
    display: block;
}

.dropdown-menu-content a {
    color: #333;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.dropdown-menu-content a:hover:not([style*="cursor: not-allowed"]) {
    background-color: #f0f0f0;
}

.dropdown-menu-content a[style*="cursor: not-allowed"]:hover {
    background-color: transparent;
}

.dropdown-divider {
    height: 1px;
    margin: 0.5rem 0;
    overflow: hidden;
    background-color: #e9ecef;
    border: 0;
}

/* Main content */
.main-content {
    padding: 2rem;
}

.setup-notice {
    background: #fff8e1;
    border: 1px solid #ffcc02;
    color: #f57f17;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.setup-notice h3 {
    margin-bottom: 1rem;
    color: #f57f17;
}

.setup-notice code {
    background: #f8f9fa;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

/* Categories grid and cards */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.category-card {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1.5rem;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.category-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #ff6b6b, #ffa726);
}

.category-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    border-color: #ff6b6b;
}

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

.category-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s;
    flex: 1;
    margin-right: 1rem;
}

.category-title:hover {
    background-color: #e9ecef;
}

.category-title-edit {
    display: none;
    flex: 1;
    margin-right: 1rem;
}

.category-title-edit input {
    width: 100%;
    padding: 0.5rem;
    border: 2px solid #ff6b6b;
    border-radius: 6px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
}

.category-title-edit input:focus {
    outline: none;
    border-color: #e55353;
}

.category-edit-buttons {
    display: none;
    gap: 0.25rem;
    margin-right: 0.5rem;
}

.item-count {
    background: #ff6b6b;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Button styles */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

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

.btn-primary {
    background: linear-gradient(135deg, #ff6b6b 0%, #ffa726 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.btn-secondary {
    background: #78909c;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #607d8b;
}

.btn-success {
    background: #66bb6a;
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #4caf50;
}

.btn-info {
    background: #29b6f6;
    color: white;
}

.btn-info:hover:not(:disabled) {
    background: #0288d1;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 15px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 25px 50px rgba(0,0,0,0.2);
}

.modal-header {
    background: linear-gradient(135deg, #26c6da 0%, #00acc1 100%);
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-weight: 300;
}

.close {
    color: white;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
}

.close:hover {
    opacity: 0.7;
}

.modal-body {
    padding: 2rem;
    max-height: 50vh;
    overflow-y: auto;
}

/* Add-item form */
.add-item-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.add-item-form input {
    flex: 1;
    min-width: 200px;
    padding: 0.75rem;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.add-item-form input:focus {
    outline: none;
    border-color: #ff6b6b;
}

.items-list > .item + .item {
    margin-top: 0.5rem;
}

.item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    transition: background-color 0.2s;
}

.item:last-child {
    margin-bottom: 0;
}

.item:hover {
    background: #e9ecef;
}

.item-text {
    flex: 1;
    margin-right: 1rem;
    word-wrap: break-word;
    line-height: 1.4;
}

.item-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.btn-small {
    padding: 0.4rem 0.8rem; /* Adjusted for consistency with old logout button */
    font-size: 0.85rem; /* Adjusted */
}

.btn-danger {
    background: #ef5350;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #e53935;
}

.btn-warning {
    background: #ffcc02;
    color: #212529;
}

.btn-warning:hover:not(:disabled) {
    background: #ffc107;
}

/* Suggestion modal */
.suggestion-modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
}

.suggestion-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

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

@keyframes slideInScale {
    from { opacity: 0; transform: scale(0.8) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.suggestion-content {
    background: linear-gradient(135deg, #29b6f6 0%, #26c3da 100%);
    color: white;
    padding: 3rem 2rem;
    border-radius: 20px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    position: relative;
    box-shadow: 0 25px 50px rgba(0,0,0,0.3);
    animation: slideInScale 0.4s ease-out;
}

.suggestion-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.suggestion-close:hover {
    background: rgba(255,255,255,0.3);
}

.suggestion-emoji {
    font-size: 4rem;
    margin-bottom: 1rem;
    display: block;
}

.suggestion-content h3 {
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    font-weight: 300;
}

.suggestion-text {
    font-size: 1.3rem;
    font-weight: 500;
    background: rgba(255,255,255,0.2);
    padding: 1.5rem;
    border-radius: 12px;
    margin: 1.5rem 0;
    line-height: 1.4;
    word-wrap: break-word;
}

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

.btn-light {
    background: rgba(255,255,255,0.9);
    color: #333;
    font-weight: 600;
}

.btn-light:hover {
    background: white;
    transform: translateY(-1px);
}

/* Edit form */
.edit-form { display: none; }

.edit-form input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}


/* Make the handle look like something you can click/drag */
.drag-handle {
  cursor: grab;
  display: inline-block;
  padding: 0 0.75rem;
  font-size: 1.2rem;
  user-select: none;
}

/* Visual feedback when dragging over another item */
.item.drag-over {
  border-top: 2px solid #333;
}

/* Loading state */
#mainAppContainer.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .login-box { padding: 1.5rem; }
    .login-box h2 { font-size: 1.5rem; }

    #mainAppContainer {
        margin-top: 0;
        margin-bottom: 0;
        border-radius: 0;
    }
    
    /* body padding handled by JS */
    
    .header { padding: 1.5rem; }

    .header-top-row {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }
    .header h1 {
        font-size: 2rem;
        text-align: center;
        margin-bottom: 0.5rem;
    }
    .user-info-logout { 
        /* This div wraps connection status, user ID, and actions menu */
        flex-direction: column; /* Stack items vertically */
        align-items: center; /* Center them */
        gap: 0.5rem; /* Space between stacked items */
        margin-left: 0;
        margin-bottom: 0.5rem;
        order: 2; /* Ensure it appears below title when stacked */
    }
    /* Forcing menu itself to align correctly within the new flex column */
    .user-actions-menu {
        width: auto; /* Allow it to size based on content */
    }
    #userActionsMenuButton {
        width: 100%; /* Make menu button full width if desired or keep auto */
        min-width: 150px; /* Example min-width */
    }
    .dropdown-menu-content { /* Adjust dropdown for mobile if needed */
        min-width: 180px; /* Ensure it's wide enough */
    }

    .header p {
        font-size: 1rem;
        margin-top: 0.25rem;
    }

    .categories-grid { grid-template-columns: 1fr; }
    .action-buttons { justify-content: center; }
    .modal-content { width: 95%; margin: 10% auto; }
    .add-item-form { flex-direction: column; }
    .add-item-form input { min-width: auto; }

    .category-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .category-title { margin-right: 0; }
    .category-title-edit { margin-right: 0; }
}
