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

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #fff;
  color: #111;
  line-height: 1.5;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem;
}

/* Header */
header {
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #ddd;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: #888;
  margin-top: 0.25rem;
}

.user-info {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: #888;
}

.user-avatar {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.storage-mode {
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  font-weight: 500;
}

.storage-mode.local {
  background: #e8f0fe;
  color: #1a73e8;
}

.storage-mode.firebase {
  background: #e6f4ea;
  color: #137333;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #ccc;
  background: #fff;
  color: #333;
  text-decoration: none;
}

.btn:hover {
  background: #f5f5f5;
}

.btn-primary {
  background: #1a73e8;
  color: #fff;
  border-color: #1a73e8;
}

.btn-primary:hover {
  background: #1557b0;
  border-color: #1557b0;
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
}

.btn-link {
  background: none;
  border: none;
  color: #1a73e8;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.4rem;
  text-decoration: none;
}

.btn-link:hover {
  text-decoration: underline;
}

.btn-link.danger {
  color: #d93025;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #666;
}

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

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #ddd;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: #666;
  cursor: pointer;
}

.tab:hover {
  color: #111;
}

.tab.active {
  color: #1a73e8;
  border-bottom-color: #1a73e8;
}

.tab-count {
  font-size: 0.7rem;
  font-weight: 500;
  background: #eee;
  padding: 0.05rem 0.35rem;
  margin-left: 0.25rem;
  color: #666;
}

.tab.active .tab-count {
  background: #d2e3fc;
  color: #1a73e8;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Section Bar */
.section-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.stats {
  font-size: 0.85rem;
  color: #555;
  font-weight: 500;
}

.actions-bar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Search */
.search-box {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid #ddd;
  font-family: inherit;
  font-size: 0.85rem;
  background: #fff;
  color: #111;
  margin-bottom: 0.75rem;
}

.search-box:focus {
  outline: none;
  border-color: #1a73e8;
}

/* Table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid #ddd;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead {
  background: #f8f9fa;
}

th {
  padding: 0.5rem 0.6rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid #ddd;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th:hover {
  background: #f0f0f0;
  color: #111;
}

td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}

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

tbody tr:hover {
  background: #f8f9fa;
}

.upcoming-payment {
  background: #fef7e0 !important;
}

.upcoming-payment:hover {
  background: #fef0c7 !important;
}

.soon-badge {
  display: inline-block;
  background: #f9ab00;
  color: #fff;
  padding: 0.1rem 0.3rem;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-left: 0.3rem;
  vertical-align: middle;
}

.frequency-badge {
  font-size: 0.75rem;
  font-weight: 500;
}

.frequency-badge.monthly {
  color: #1a73e8;
}

.frequency-badge.yearly {
  color: #7b1fa2;
}

.category-badge {
  font-size: 0.75rem;
  color: #555;
}

.item-note {
  font-size: 0.75rem;
  color: #888;
}

.item-actions {
  display: flex;
  gap: 0.25rem;
  white-space: nowrap;
}

.icon-btn {
  padding: 0.25rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  font-family: inherit;
}

.icon-btn.edit {
  color: #1a73e8;
}

.icon-btn.edit:hover {
  text-decoration: underline;
}

.icon-btn.delete {
  color: #d93025;
}

.icon-btn.delete:hover {
  text-decoration: underline;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

.modal.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
}

.modal-content {
  position: relative;
  background: #fff;
  padding: 1.25rem;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1;
  border: 1px solid #ddd;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #eee;
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
}

.close-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #ddd;
  background: #fff;
  font-size: 1.1rem;
  color: #666;
  cursor: pointer;
}

.close-btn:hover {
  background: #f5f5f5;
  color: #111;
}

/* Form */
.form-group {
  margin-bottom: 0.75rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
  font-size: 0.8rem;
  color: #333;
}

.required {
  color: #d93025;
}

.form-input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ddd;
  font-family: inherit;
  font-size: 0.85rem;
  background: #fff;
  color: #111;
}

.form-input:focus {
  outline: none;
  border-color: #1a73e8;
}

.form-input::placeholder {
  color: #aaa;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eee;
}

.form-actions .btn {
  flex: 1;
}

/* Notification */
.notification {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.6rem 1.25rem;
  z-index: 2000;
  max-width: calc(100% - 2rem);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid;
}

.notification.success {
  background: #e6f4ea;
  color: #137333;
  border-color: #ceead6;
}

.notification.error {
  background: #fce8e6;
  color: #c5221f;
  border-color: #f5c6c2;
}

.notification.info {
  background: #e8f0fe;
  color: #1a73e8;
  border-color: #d2e3fc;
}

/* Footer */
footer {
  text-align: center;
  padding: 1.5rem 0.5rem;
  margin-top: 2rem;
  color: #999;
  font-size: 0.75rem;
  border-top: 1px solid #eee;
}

footer a {
  color: #1a73e8;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Mobile */
@media (max-width: 640px) {
  .container {
    padding: 0.5rem;
  }

  .section-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .actions-bar {
    flex-wrap: wrap;
  }

  .hide-mobile {
    display: none;
  }

  .btn {
    min-height: 44px;
  }

  .tab {
    min-height: 44px;
    flex: 1;
    text-align: center;
  }

  .icon-btn {
    min-height: 44px;
    padding: 0.4rem 0.6rem;
  }

  /* Modal full screen on mobile */
  .modal.active {
    align-items: stretch;
  }

  .modal-content {
    max-width: 100%;
    max-height: 100vh;
    border: none;
  }

  .modal-header {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
    margin: -1.25rem -1.25rem 1rem -1.25rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #eee;
  }

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

  .form-input {
    font-size: 16px; /* Prevent iOS zoom */
  }

  .form-actions {
    position: sticky;
    bottom: 0;
    background: #fff;
    margin: 1rem -1.25rem -1.25rem -1.25rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid #eee;
  }

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

/* Print */
@media print {
  .actions-bar,
  .search-box,
  .item-actions,
  header,
  footer {
    display: none !important;
  }

  .container {
    max-width: 100%;
  }
}