/* ===== ДОРДОЙ CRM — Mobile First ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 260px;
  --bg:        #f4f5f7;
  --surface:   #ffffff;
  --border:    #e5e7eb;
  --text:      #111827;
  --text2:     #6b7280;
  --text3:     #9ca3af;
  --accent:    #2563eb;
  --accent-h:  #1d4ed8;
  --accent-bg: #eff6ff;
  --green:     #16a34a;
  --green-bg:  #f0fdf4;
  --red:       #dc2626;
  --red-bg:    #fef2f2;
  --orange:    #ea580c;
  --orange-bg: #fff7ed;
  --radius:    10px;
  --shadow:    0 1px 4px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.1);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ========== LAYOUT ========== */
.dashboard { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.dashboard.sidebar-open .sidebar { transform: translateX(0); }
.dashboard.sidebar-open .overlay { display: block; }

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  font-size: 1.25rem; font-weight: 700;
  color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--border); display: block;
}
.sidebar-nav { flex: 1; padding: .5rem 0; }
.sidebar-section {
  padding: .7rem 1.25rem .3rem; margin-top: .5rem;
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text3); border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: .45rem;
}
.sidebar-section::before { content:''; width:7px; height:7px; border-radius:50%; flex-shrink:0; }
.sidebar-section:first-child { border-top: none; margin-top: .25rem; }
.sidebar-section:nth-of-type(1)::before { background: var(--accent); }
.sidebar-section:nth-of-type(2)::before { background: var(--green); }
.sidebar-section:nth-of-type(3)::before { background: var(--orange); }
.sidebar-link {
  display: flex; align-items: center;
  padding: .75rem 1.25rem; min-height: 48px;
  color: var(--text2); text-decoration: none;
  font-size: .95rem; font-weight: 450;
  transition: all .15s; border-left: 3px solid transparent;
}
.sidebar-link:hover  { background: var(--bg); color: var(--text); }
.sidebar-link.active { background: var(--accent-bg); color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); }

.main { flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: .9rem 1rem; display: flex; align-items: center; gap: .75rem;
  position: sticky; top: 0; z-index: 100;
}
.topbar-title { font-size: 1.1rem; font-weight: 600; }
.menu-toggle {
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: .4rem .65rem; font-size: 1.2rem; cursor: pointer; color: var(--text);
  min-width: 44px; min-height: 44px; flex-shrink: 0;
}
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 150;
  -webkit-tap-highlight-color: transparent;
}
.content { flex: 1; padding: 1rem; }

/* ========== CARDS ========== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card-title { font-size: 1rem; font-weight: 600; }
.card-header-mobile {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: .75rem; gap: .5rem;
}

/* ========== TABLES ========== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .7rem .75rem; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text2); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; background: var(--bg); }
tbody tr:active { background: #fafafa; }
td a { color: var(--accent); text-decoration: none; }

/* Мобильные карточки — применяй class="card-table" к table */
@media (max-width: 767px) {
  .card-table thead { display: none; }
  .card-table, .card-table tbody, .card-table tr, .card-table td { display: block; }
  .card-table tr {
    border: 1px solid var(--border); border-radius: 10px;
    margin-bottom: .6rem; padding: .5rem .75rem; background: var(--surface);
  }
  .card-table td {
    display: flex; justify-content: space-between; align-items: center;
    padding: .5rem 0; border-bottom: 1px solid var(--border);
    font-size: .9rem; min-height: 40px; gap: .5rem;
  }
  .card-table td:last-child { border-bottom: none; }
  .card-table td::before {
    content: attr(data-label); font-weight: 600; font-size: .72rem;
    color: var(--text2); text-transform: uppercase; letter-spacing: .04em;
    white-space: nowrap; flex-shrink: 0; min-width: 70px;
  }
  .card-table td[data-label=""]::before, .card-table td:not([data-label])::before { display: none; }
}

/* ========== FORMS ========== */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: .85rem; font-weight: 500; color: var(--text2); margin-bottom: .35rem; }
input, select, textarea {
  width: 100%; padding: .75rem .85rem;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 1rem; font-family: inherit;
  background: var(--surface); transition: border-color .15s;
  -webkit-appearance: none; appearance: none; min-height: 48px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; min-height: 80px; }
.form-row { display: flex; flex-direction: column; gap: .85rem; }
.form-inline { display: flex; flex-direction: column; gap: .5rem; }
.form-inline .form-group { margin-bottom: 0; }
.actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .35rem; padding: .7rem 1.1rem;
  border: none; border-radius: 8px; font-size: 1rem; font-weight: 500;
  cursor: pointer; transition: all .15s; text-decoration: none;
  line-height: 1.4; white-space: nowrap; min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .8; transform: scale(.97); }
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-h); }
.btn-secondary { background: transparent; color: var(--text2); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger    { background: transparent; color: var(--red); border: 1.5px solid var(--border); }
.btn-danger:hover   { background: var(--red-bg); }
.btn-success   { background: var(--green); color: #fff; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; min-height: 38px; border-radius: 6px; }
.btn-logout { background: none; border: none; color: var(--text2); cursor: pointer; font-size: .9rem; padding: .5rem 0; min-height: 44px; }
.btn-logout:hover { color: var(--red); }

/* ========== BADGES ========== */
.badge { display: inline-block; padding: .2rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-new        { background: var(--accent-bg); color: var(--accent); }
.badge-in_transit { background: var(--orange-bg); color: var(--orange); }
.badge-delivered  { background: var(--green-bg);  color: var(--green); }
.badge-canceled   { background: var(--red-bg);    color: var(--red); }
.badge-free       { background: var(--green-bg);  color: var(--green); }
.badge-busy       { background: var(--orange-bg); color: var(--orange); }
.badge-ADMIN      { background: var(--accent-bg); color: var(--accent); }
.badge-CLIENT     { background: var(--green-bg);  color: var(--green); }
.badge-COURIER    { background: var(--orange-bg); color: var(--orange); }

/* ========== CHIPS ========== */
.chips-wrap { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .35rem; }
.chip {
  padding: .4rem .85rem; border-radius: 99px; font-size: .9rem;
  border: 1.5px solid var(--border); background: var(--surface);
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: all .15s; min-height: 40px; display: flex; align-items: center;
}
.chip:active  { opacity: .8; }
.chip.selected { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

/* ========== AUTOCOMPLETE ========== */
.ac-wrap { position: relative; }
.ac-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 300;
  background: var(--surface); border: 1.5px solid var(--border); border-top: none;
  border-radius: 0 0 10px 10px; box-shadow: var(--shadow-md);
  display: none; max-height: 260px; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.ac-dropdown.open { display: block; }
.ac-item { padding: .85rem .9rem; cursor: pointer; font-size: .95rem; border-bottom: 1px solid var(--border); min-height: 52px; display: flex; flex-direction: column; justify-content: center; }
.ac-item:last-child { border-bottom: none; }
.ac-item:active { background: var(--accent-bg); }
.ac-item .ac-sub { font-size: .8rem; color: var(--text2); margin-top: .1rem; }

/* ========== PHOTOS ========== */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: .5rem; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

/* ========== SEARCH ========== */
.search-result { display: flex; gap: .85rem; padding: 1rem 0; border-bottom: 1px solid var(--border); }
.search-result:last-child { border-bottom: none; }
.search-result .info { flex: 1; min-width: 0; }
.search-result .info h3 { font-size: 1rem; margin-bottom: .2rem; }
.search-result .info p  { font-size: .85rem; color: var(--text2); }
.search-result .price   { font-weight: 700; font-size: 1rem; white-space: nowrap; }

/* ========== LOGIN ========== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 1rem; }
.login-card { width: 100%; max-width: 380px; padding: 1.75rem; }
.login-card h1 { font-size: 1.5rem; text-align: center; margin-bottom: 1.5rem; }

/* ========== STATES ========== */
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text2); font-size: .95rem; }
.alert { padding: .75rem .9rem; border-radius: 8px; font-size: .9rem; margin-bottom: .85rem; }
.alert-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid #fecaca; }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid #bbf7d0; }
.alert-toast { margin: .85rem 1rem 0; display: flex; align-items: center; justify-content: space-between; gap: .75rem; animation: slideDown .3s ease; }
.alert-close { background: none; border: none; cursor: pointer; font-size: 1.1rem; color: inherit; opacity: .6; padding: .25rem; min-width: 32px; }
.alert-close:hover { opacity: 1; }
@keyframes slideDown { from { opacity:0; transform:translateY(-8px); } to { opacity:1; transform:translateY(0); } }
.breadcrumb { font-size: .85rem; color: var(--text2); margin-bottom: .85rem; }
.breadcrumb a { color: var(--accent); text-decoration: none; }

/* ========== STATS ========== */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; }
.stat-card .stat-label { font-size: .72rem; color: var(--text2); text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; margin-top: .15rem; }

/* ========== ORDER STATUS ========== */
.status-form { margin: 0; }
.status-select {
  padding: .25rem .5rem; border-radius: 99px; font-size: .82rem; font-weight: 600;
  border: 1.5px solid transparent; cursor: pointer; min-height: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .4rem center; background-size: 8px; padding-right: 1.6rem;
  -webkit-appearance: none; appearance: none;
}
.status-select[data-current="new"]        { background-color:#eff6ff; color:#2563eb; border-color:#bfdbfe; }
.status-select[data-current="in_transit"] { background-color:#fff7ed; color:#ea580c; border-color:#fed7aa; }
.status-select[data-current="delivered"]  { background-color:#f0fdf4; color:#16a34a; border-color:#bbf7d0; }
.status-select[data-current="canceled"]   { background-color:#fef2f2; color:#dc2626; border-color:#fecaca; }

/* ========== DESKTOP ≥ 768px ========== */
@media (min-width: 768px) {
  .content { padding: 1.5rem 1.75rem; max-width: 1100px; }
  .card { padding: 1.25rem; }
  .topbar { padding: .85rem 1.75rem; }
  .alert-toast { margin: .85rem 1.75rem 0; }
  .sidebar { transform: translateX(0); }
  .main { margin-left: var(--sidebar-w); }
  .menu-toggle { display: none; }
  .form-row { flex-direction: row; }
  .form-row > * { flex: 1; }
  .form-inline { flex-direction: row; align-items: flex-end; }
  .form-inline .btn { width: auto; }
  input, select, textarea { padding: .55rem .75rem; font-size: .9rem; min-height: 40px; }
  .btn { padding: .5rem 1rem; font-size: .88rem; min-height: 40px; }
  .btn-sm { padding: .3rem .65rem; font-size: .8rem; min-height: 34px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .actions { flex-direction: row; }
  .actions .btn { width: auto; }
  /* Таблицы на десктопе — обычный вид */
  .card-table thead { display: table-header-group; }
  .card-table, .card-table tbody, .card-table tr, .card-table td { display: revert; }
  .card-table tr { border: none; border-radius: 0; margin: 0; padding: 0; }
  .card-table td { border-bottom: 1px solid var(--border); padding: .65rem .75rem; font-size: .88rem; }
  .card-table td::before { display: none; }
}
