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

:root {
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-focus: #93c5fd;
  --accent: #2563eb;
  --accent-light: #eff6ff;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --surface: #f9fafb;
  --page-bg: #f4f6f9;
  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 4px 12px rgba(15,23,42,.04);
  --radius: 10px;
  --block-gap: 14px;
  --max-width: 920px;
  --header-h: 52px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--page-bg);
  line-height: 1.55;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
}

.nav {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav-brand:hover { text-decoration: none; }

.nav-links { display: flex; gap: 20px; }

.nav-link {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}

.nav-link:hover,
.nav-link.active {
  color: var(--accent);
  text-decoration: none;
}

/* Main */
.main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 16px 56px;
}

/* Search */
.search-bar { margin-bottom: 20px; }

.search-input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: #fff;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.btn:hover {
  border-color: #d1d5db;
  background: var(--surface);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  border: none;
  background: none;
  color: var(--text-muted);
  padding: 4px 8px;
}

.btn-ghost:hover { color: var(--danger); }

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; margin-top: 6px; }

.btn-icon {
  padding: 6px;
  font-size: 1.1rem;
  line-height: 1;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
}

.btn-icon:hover { color: var(--danger); background: #fef2f2; }

.btn-copy {
  padding: 6px;
  border: none;
  background: none;
  color: #9ca3af;
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.btn-copy:hover { color: var(--accent); background: var(--accent-light); }

.btn-tel {
  padding: 6px;
  color: var(--accent);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  border-radius: 4px;
}

.btn-tel:hover { background: var(--accent-light); text-decoration: none; }

/* Cards & sections */
.card-block {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: var(--block-gap);
}

.company-info-block .btn-add-company-phone {
  margin-top: 6px;
}

#company-phones-list .field-row {
  margin-bottom: 8px;
}

.field-textarea#f-comment,
.field-textarea.field-textarea {
  min-height: 64px;
}

.section { margin-bottom: 0; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* Company list */
.company-list { list-style: none; }

.company-item {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}

.company-item a {
  display: block;
  padding: 14px 6px;
  color: var(--text);
  text-decoration: none;
}

.company-item:hover { background: var(--surface); }
.company-item a:hover { text-decoration: none; }

.company-name { font-weight: 600; font-size: 1rem; }

.company-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

.empty-state.compact { padding: 16px 8px; font-size: 0.85rem; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.back-link {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: inline-block;
}

/* Form fields */
.field { margin-bottom: 12px; }

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.field-input,
.field-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: var(--surface);
}

.field-input:focus,
.field-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: #fff;
}

.field-textarea { resize: vertical; min-height: 72px; }

.field-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.field-row .field-input,
.field-row .field-textarea { flex: 1; min-width: 0; }

/* Contacts + Reminders grid */
.contacts-reminders-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  margin-bottom: 16px;
}

.contacts-col .contact-card { margin-bottom: 10px; }

.contact-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
}

.contact-subsection { margin-top: 8px; }

.contact-subsection-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Reminders sidebar */
.reminders-col .reminder-card { margin-bottom: 8px; }

.reminder-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--accent-light);
  border-color: #bfdbfe;
}

.reminder-card.active-card {
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
}

.reminder-card.dismissed {
  opacity: 0.6;
  background: var(--surface);
  border-color: var(--border);
}

.reminder-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.reminder-card-date { font-size: 0.8rem; font-weight: 600; color: var(--accent); }

.reminder-card-text {
  font-size: 0.85rem;
  color: var(--text);
  word-break: break-word;
  flex: 1;
}

.reminder-dismissed-label { font-size: 0.7rem; color: var(--text-muted); }

.reminder-add-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.archive-link {
  display: block;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.archive-link:hover { color: var(--accent); }

/* History */
.history-item {
  border-left: 3px solid var(--accent);
  padding: 0 0 14px 12px;
  margin-bottom: 12px;
}

.history-date {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.history-text {
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1;
}

.history-text-row { align-items: flex-start; }

.btn-load-more {
  width: 100%;
  margin: 8px 0 4px;
}

/* Calendar reminders page */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}

.calendar-date {
  font-size: 1.05rem;
  font-weight: 600;
  min-width: 200px;
  text-align: center;
}

.calendar-picker-wrap {
  text-align: center;
  margin-bottom: 20px;
}

.calendar-picker-wrap .field-input {
  width: auto;
  display: inline-block;
}

.reminder-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}

.reminder-item:hover { border-color: #bfdbfe; }

.history-reminder-tag {
  font-size: 0.8rem;
  margin: 4px 0 6px;
}

.history-reminder-tag.outstanding {
  color: var(--accent);
  font-weight: 600;
}

.history-reminder-tag.done {
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0.7;
}

.history-item.has-reminder-outstanding {
  border-left-color: var(--accent);
}

.history-add-form {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reminder-item.outstanding {
  border-color: #bfdbfe;
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
}

.reminder-item.outstanding .reminder-company {
  color: var(--accent);
}

.reminder-item.past-reminder {
  opacity: 0.7;
}

.reminder-item.past-reminder .reminder-company {
  font-weight: 500;
}

.reminder-item a { color: var(--text); text-decoration: none; }
.reminder-item a:hover { text-decoration: none; }

.reminder-company { font-weight: 600; }

.reminder-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.reminder-badge-off {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: #e5e7eb;
  padding: 2px 8px;
  border-radius: 4px;
}

/* Delete company */
.delete-company-wrap {
  text-align: center;
  margin-top: 32px;
  padding-top: 16px;
}

.btn-delete-company {
  border: none;
  background: none;
  color: #d1d5db;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 8px;
}

.btn-delete-company:hover { color: #9ca3af; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 10px 18px;
  border: none;
  background: none;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { animation: fadeIn .15s ease; }

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

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  z-index: 200;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}

.toast.show { opacity: 1; }

/* Login */
.login-page {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 22px;
  font-size: 0.95rem;
}

.login-form .field { margin-bottom: 14px; }

.login-submit {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
}

.login-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-bottom: 10px;
  text-align: center;
}

.nav-logout {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font: inherit;
}

/* Mobile */
@media (max-width: 700px) {
  .contacts-reminders-grid {
    grid-template-columns: 1fr;
  }

  .reminders-col { order: -1; }

  .page-header { flex-direction: column; align-items: flex-start; }

  .calendar-date { min-width: auto; font-size: 0.95rem; }

  .field-row { flex-wrap: wrap; }

  .btn-tel, .btn-copy { padding: 8px; }
}

@media (max-width: 400px) {
  .main { padding: 16px 12px 48px; }
  .card-block { padding: 12px; }
}
