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

:root {
    --primary: #2196F3;
    --primary-dark: #1976D2;
    --primary-light: #BBDEFB;
    --accent: #FF4081;
    --text: #212121;
    --text-secondary: #757575;
    --divider: #BDBDBD;
    --background: #fafafa;
    --surface: #ffffff;
    --surface-hover: #f5f5f5;
    --border: #e0e0e0;
    --error: #f44336;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    --shadow-md: 0 3px 6px rgba(0,0,0,0.15), 0 2px 4px rgba(0,0,0,0.12);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.15), 0 3px 6px rgba(0,0,0,0.10);
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #42A5F5;
        --primary-dark: #2196F3;
        --primary-light: #1565C0;
        --accent: #FF4081;
        --text: #ffffff;
        --text-secondary: #B0B0B0;
        --divider: #424242;
        --background: #121212;
        --surface: #1E1E1E;
        --surface-hover: #2D2D2D;
        --border: #424242;
        --error: #ef5350;
        --shadow-sm: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.5);
        --shadow-md: 0 3px 6px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.5);
        --shadow-lg: 0 10px 20px rgba(0,0,0,0.4), 0 3px 6px rgba(0,0,0,0.5);
    }
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text);
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Auth Screen */
#auth-screen {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-lg);
}

.logo {
    text-align: center;
    margin-bottom: 24px;
}

.logo h1 {
  color: white;
  font-size: 24px;
  font-weight: 600;
  margin-top: 8px;
}

.tabs {
    display: flex;
    margin-bottom: 24px;
    background: var(--surface-hover);
    border-radius: 8px;
    padding: 4px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

.input-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.input-group input {
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    background: var(--surface);
    color: var(--text);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.input-group input::placeholder {
    color: var(--text-secondary);
}

.btn {
    padding: 14px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

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

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

.error-message {
    color: var(--error);
    font-size: 14px;
    text-align: center;
    min-height: 20px;
}

/* App Header */
.app-header {
    background: var(--primary);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  text-align: center;
  margin: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 4px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.2);
}

.btn-icon svg {
    width: 24px;
    height: 24px;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

/* Lists Grid */
.lists-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

@media (max-width: 360px) {
    .lists-grid {
        grid-template-columns: 1fr;
    }
}

.list-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.list-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.list-card:active {
    transform: scale(0.98);
}

.list-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.list-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.list-card-badge {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    text-transform: uppercase;
}

.list-card-meta {
    font-size: 13px;
    color: var(--text-secondary);
}

/* FAB */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 100;
}

.fab:hover {
    box-shadow: var(--shadow-lg);
    transform: scale(1.05);
}

.fab:active {
    transform: scale(0.95);
}

/* Items List */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.item {
    background: var(--surface);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
}

.item:hover {
    box-shadow: var(--shadow-md);
}

.item-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid var(--divider);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.item-checkbox:hover {
    border-color: var(--primary);
}

.item-checkbox.checked {
    background: var(--primary);
    border-color: var(--primary);
}

.item-checkbox.checked svg {
    display: block;
}

.item-checkbox svg {
    display: none;
    width: 16px;
    height: 16px;
}

.item-checkbox svg path {
    fill: white;
}

.item-content {
    flex: 1;
    min-width: 0;
}

.item-name {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item.checked .item-name {
    text-decoration: line-through;
    color: var(--text-secondary);
}

.item-quantity {
    font-size: 13px;
    color: var(--text-secondary);
}

.item-delete {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s;
    padding: 0;
}

.item:hover .item-delete {
    opacity: 1;
}

.item-delete:hover {
    background: #ffebee;
    color: var(--error);
}

.item-delete svg {
    width: 18px;
    height: 18px;
}

/* Add Item Bar */
.add-item-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  box-shadow: 0 -2px 4px rgba(0,0,0,0.05);
  flex-wrap: wrap;
}

.add-item-bar input {
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.2s;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}

.add-item-bar input:focus {
  outline: none;
  border-color: var(--primary);
}

.add-item-bar input::placeholder {
  color: var(--text-secondary);
}

#item-name {
  flex: 1;
}

#item-quantity {
  width: 80px;
  min-width: 60px;
  text-overflow: ellipsis;
}

.add-item-bar .btn {
  padding: 12px 16px;
  min-width: 48px;
}

@media (max-width: 400px) {
  .add-item-bar {
    padding: 12px;
  }

  .add-item-bar input {
    padding: 10px 12px;
  }

  #item-name {
    width: 100%;
    flex: none;
  }

  #item-quantity {
    flex: 1;
    min-width: 60px;
    width: auto;
  }
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--text-secondary);
    text-align: center;
}

.empty-state svg {
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 4px;
}

.empty-state .subtitle {
    font-size: 14px;
    color: var(--divider);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideUp 0.3s ease;
}

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

.modal-content h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.modal-content p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.modal-content input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 16px;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-actions .btn {
    padding: 12px 24px;
}

/* Live Indicator */
.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--primary);
    font-weight: 500;
    padding: 4px 8px;
    background: var(--primary-light);
    border-radius: 12px;
    margin-left: 8px;
}

.live-indicator::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1001;
  opacity: 0;
  transition: all 0.3s;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Connection Status */
.connection-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 8px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    z-index: 1002;
    transform: translateY(-100%);
    transition: transform 0.3s;
}

.connection-status.offline {
    background: var(--error);
    color: white;
    transform: translateY(0);
}

.connection-status.connecting {
    background: #ff9800;
    color: white;
    transform: translateY(0);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Safe area for mobile */
@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }
    
    .fab {
        bottom: max(24px, calc(24px + env(safe-area-inset-bottom)));
        right: max(24px, calc(24px + env(safe-area-inset-right)));
    }
}

/* Touch device optimizations */
@media (hover: none) {
    .item-delete {
        opacity: 1;
    }
    
    .list-card:hover {
        transform: none;
    }
}
