/* ===== CSS Variables / Themes ===== */
:root {
  --sidebar-bg: #fff;
  --sidebar-text: #333;
  --sidebar-text-secondary: #888;
  --sidebar-hover-bg: #f5f5f5;
  --sidebar-active-bg: #e6f7ff;
  --sidebar-active-border: #1890ff;
  --sidebar-header-border: #f0f0f0;
  --sidebar-toggle-bg: #f0f0f0;
  --sidebar-toggle-hover: #d9d9d9;
  --sidebar-toggle-color: #888;
  --body-bg: #f0f2f5;
  --text-color: #333;
  --text-heading: #222;
  --card-bg: #fff;
  --card-shadow: 0 1px 4px rgba(0,0,0,.06);
  --card-border: #f0f0f0;
  --input-bg: #fff;
  --input-border: #d9d9d9;
  --input-color: #333;
  --table-header-bg: #fafafa;
  --table-border: #f0f0f0;
  --table-hover: #fafafa;
  --modal-overlay: rgba(0,0,0,.45);
  --modal-bg: #fff;
  --modal-border: #f0f0f0;
  --alert-info-bg: #e6f7ff;
  --alert-info-border: #91d5ff;
  --alert-info-color: #0050b3;
  --alert-warn-bg: #fff7e6;
  --alert-warn-color: #613400;
  --alert-error-bg: #fff2f0;
  --alert-error-border: #ffccc7;
  --alert-error-color: #a8071a;
  --alert-success-bg: #f6ffed;
  --alert-success-border: #b7eb8f;
  --alert-success-color: #135200;
  --stat-card-bg: #fff;
  --stat-label-color: #888;
  --detail-border: #f5f5f5;
  --detail-label: #888;
  --detail-value: #333;
  --login-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  --login-card-bg: #fff;
  --login-card-shadow: 0 2px 12px rgba(0,0,0,.08);
  --loading-color: #888;
  --footer-text: #bbb;
}

/* Dark theme */
body.dark-theme {
  --sidebar-bg: #1f1f1f;
  --sidebar-text: rgba(255,255,255,.85);
  --sidebar-text-secondary: rgba(255,255,255,.45);
  --sidebar-hover-bg: rgba(255,255,255,.08);
  --sidebar-active-bg: rgba(255,255,255,.08);
  --sidebar-active-border: #1890ff;
  --sidebar-header-border: rgba(255,255,255,.1);
  --sidebar-toggle-bg: rgba(255,255,255,.1);
  --sidebar-toggle-hover: rgba(255,255,255,.2);
  --sidebar-toggle-color: rgba(255,255,255,.45);
  --body-bg: #141414;
  --text-color: rgba(255,255,255,.85);
  --text-heading: rgba(255,255,255,.85);
  --card-bg: #1f1f1f;
  --card-shadow: 0 1px 4px rgba(0,0,0,.3);
  --card-border: #303030;
  --input-bg: #2a2a2a;
  --input-border: #434343;
  --input-color: rgba(255,255,255,.85);
  --table-header-bg: #1a1a1a;
  --table-border: #303030;
  --table-hover: #2a2a2a;
  --modal-overlay: rgba(0,0,0,.65);
  --modal-bg: #1f1f1f;
  --modal-border: #303030;
  --alert-info-bg: #111d2c;
  --alert-info-border: #153450;
  --alert-info-color: #91d5ff;
  --alert-warn-bg: #2b1d0a;
  --alert-warn-color: #ffd591;
  --alert-error-bg: #2a1215;
  --alert-error-border: #58181c;
  --alert-error-color: #ffa39e;
  --alert-success-bg: #162312;
  --alert-success-border: #274916;
  --alert-success-color: #b7eb8f;
  --stat-card-bg: #1f1f1f;
  --stat-label-color: rgba(255,255,255,.45);
  --detail-border: #303030;
  --detail-label: rgba(255,255,255,.45);
  --detail-value: rgba(255,255,255,.85);
  --login-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  --login-card-bg: #1f1f1f;
  --login-card-shadow: 0 2px 12px rgba(0,0,0,.3);
  --loading-color: rgba(255,255,255,.45);
  --footer-text: rgba(255,255,255,.25);
}

/* ===== Базовые стили ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: clamp(14px, 0.6vw + 11px, 18px); }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; font-size: 1rem; line-height: 1.5; color: var(--text-color); background: var(--body-bg); transition: background .3s, color .3s; }
a { color: #1890ff; text-decoration: none; }
a:hover { color: #40a9ff; }
h1, h2, h3, h4 { font-weight: 600; color: var(--text-heading); }
h2 { font-size: clamp(18px, 1vw + 12px, 24px); margin-bottom: 16px; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ===== Layout ===== */
.layout { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar { width: 220px; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 1000; transition: width .2s, background .3s; overflow: hidden; box-shadow: 2px 0 8px rgba(0,0,0,.06); }
.sidebar.collapsed { width: 56px; }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--sidebar-header-border); min-height: 64px; gap: 8px; }
.sidebar-title { overflow: hidden; white-space: nowrap; flex: 1; min-width: 0; }
.sidebar-title h2 { font-size: 16px; font-weight: 600; color: var(--sidebar-text); margin: 0; }
.sidebar-subtitle { font-size: 11px; color: var(--sidebar-text-secondary); margin-top: 1px; }
.sidebar.collapsed .sidebar-title { opacity: 0; width: 0; flex: 0; }

.sidebar-collapse-btn { background: none; border: none; color: var(--sidebar-text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 6px; flex-shrink: 0; transition: all .2s; }
.sidebar-collapse-btn:hover { color: var(--sidebar-text); background: var(--sidebar-hover-bg); }
.sidebar.collapsed .sidebar-collapse-btn { transform: rotate(180deg); }
.sidebar-close-btn { display: none; background: none; border: none; color: var(--sidebar-text-secondary); cursor: pointer; width: 32px; height: 32px; border-radius: 6px; align-items: center; justify-content: center; flex-shrink: 0; }

.sidebar-body { flex: 1; padding: 8px 0; overflow-y: auto; overflow-x: hidden; }
.sidebar-body a { display: flex; align-items: center; gap: 12px; padding: 10px 16px; color: var(--sidebar-text); text-decoration: none; font-size: 14px; transition: all .15s; white-space: nowrap; border-left: 3px solid transparent; margin: 1px 0; }
.sidebar-body a:hover { background: var(--sidebar-hover-bg); }
.sidebar-body a.active { color: #1890ff; background: var(--sidebar-active-bg); border-left-color: #1890ff; font-weight: 500; }
.sidebar-body .menu-icon { width: 24px; text-align: center; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 18px; line-height: 1; }
.sidebar-body .menu-icon svg { display: block; }
.sidebar-body .menu-text { transition: opacity .15s; overflow: hidden; }
.sidebar.collapsed .menu-text { opacity: 0; width: 0; }
.sidebar.collapsed .sidebar-body a { justify-content: center; padding: 10px 0; border-left: none; }
.sidebar.collapsed .sidebar-body a.active { border-left: none; background: var(--sidebar-active-bg); }

.menu-divider { height: 1px; background: var(--sidebar-header-border); margin: 4px 12px; }

.sidebar-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--sidebar-header-border); gap: 8px; min-height: 52px; }
.sidebar-user { font-size: 13px; color: var(--sidebar-text); overflow: hidden; white-space: nowrap; }
.sidebar.collapsed .sidebar-user { display: none; }
.sidebar-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.sidebar-action-btn { background: none; border: none; color: var(--sidebar-text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 4px; transition: all .2s; padding: 0; }
.sidebar-action-btn:hover { color: var(--sidebar-text); background: var(--sidebar-hover-bg); }
.sidebar-logout:hover { color: #ff4d4f !important; }
.sidebar.collapsed .sidebar-actions { justify-content: center; width: 100%; }

.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.45); z-index: 999; }
.sidebar.mobile-open ~ .sidebar-overlay { display: block; }

/* Mobile transform always available */
.sidebar.mobile-open { transform: translateX(0); }

/* ===== Main content ===== */
.main-content { margin-left: 220px; flex: 1; padding: 24px; min-height: 100vh; transition: margin-left .2s; }
.sidebar.collapsed + .main-content { margin-left: 60px; }

/* ===== Card ===== */
.card { background: var(--card-bg); border-radius: 8px; box-shadow: var(--card-shadow); margin-bottom: 16px; transition: background .3s, box-shadow .3s; }
.card-head { padding: 14px 20px; border-bottom: 1px solid var(--card-border); font-weight: 600; font-size: 15px; color: var(--text-heading); transition: border-color .3s; }
.card-body { padding: 20px; }

/* ===== Stat cards ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--stat-card-bg); border-radius: 8px; padding: 20px; box-shadow: var(--card-shadow); transition: all .3s ease; }
.stat-card:hover { transform: translateY(-5px); box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.stat-card .stat-value { font-size: 28px; font-weight: 700; }
.stat-card .stat-label { font-size: 13px; color: var(--stat-label-color); margin-top: 4px; }

/* ===== Form ===== */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.form-row label { font-size: clamp(12px, 0.3vw + 10px, 14px); color: var(--text-heading); display: block; margin-bottom: 3px; font-weight: 500; }
.form-input, .form-row input[type="date"], .form-row input[type="number"], .form-row input[type="text"], .form-row select, .form-row textarea { padding: 5px 8px; border: 1px solid var(--input-border); border-radius: 6px; background: var(--input-bg); color: var(--input-color); height: 32px; transition: background .3s, border-color .3s, color .3s; box-sizing: border-box; }
.form-input:focus, .form-row input:focus, .form-row select:focus, .form-row textarea:focus { border-color: #40a9ff; outline: none; box-shadow: 0 0 0 2px rgba(24,144,255,.2); }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 13px; color: var(--stat-label-color); margin-bottom: 4px; font-weight: 500; }
.form-group .form-input { width: 100%; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-weight: 400; font-size: 13px; margin-bottom: 4px; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.form-row > div { flex: 1; min-width: 140px; max-width: 220px; display: flex; flex-direction: column; justify-content: flex-end; }
.form-row > div > br { display: none; }
.form-row input[type="number"] { width: 100%; }
.form-row input[type="text"] { width: 100%; }
.form-row select { width: 100%; padding: 5px 8px; }
.form-row textarea { width: 100%; min-height: 60px; resize: vertical; height: auto; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border: 1px solid var(--input-border); border-radius: 6px; background: var(--card-bg); color: var(--text-color); cursor: pointer; font-size: 14px; line-height: 1.5; transition: all .2s; height: 32px; }
.btn:hover { border-color: #40a9ff; color: #40a9ff; }
.btn-primary { background: #1890ff; border-color: #1890ff; color: #fff; }
.btn-primary:hover { background: #40a9ff; border-color: #40a9ff; color: #fff; }
.btn-sm { font-size: 13px; padding: 4px 12px; height: 30px; }
.btn-link { border: none; background: none; color: #1890ff; padding: 0 6px; height: auto; }
.btn-link:hover { color: #40a9ff; }
.btn-link svg { width: 18px; height: 18px; vertical-align: middle; }
.btn-warning { background: #faad14; border-color: #faad14; color: #fff; }
.btn-warning:hover { background: #ffc53d; border-color: #ffc53d; color: #fff; }
.btn-success { background: #52c41a; border-color: #52c41a; color: #fff; }
.btn-success:hover { background: #73d13d; border-color: #73d13d; color: #fff; }
.btn .icon { font-size: 14px; }
.btn.disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* ===== Table ===== */
.table { width: 100%; border-collapse: collapse; }
.table th { background: var(--table-header-bg); padding: 12px 16px; text-align: left; font-weight: 600; font-size: 13px; color: var(--text-color); border-bottom: 1px solid var(--table-border); transition: background .3s, border-color .3s; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--table-border); font-size: 14px; transition: border-color .3s; }
.table tr:hover td { background: var(--table-hover); }

/* ===== Tag / Status badges ===== */
.tag { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 12px; line-height: 1.5; color: #fff; }
.tag-blue { background: #1890ff; }
.tag-green { background: #52c41a; }
.tag-orange { background: #faad14; }
.tag-red { background: #ff4d4f; }
.tag-purple { background: #722ed1; }
.tag-default { background: #d9d9d9; color: #555; }

/* ===== Alert ===== */
.alert { padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 8px; }
.alert-info { background: var(--alert-info-bg); border: 1px solid var(--alert-info-border); color: var(--alert-info-color); }
.alert-warning { background: var(--alert-warn-bg); border-left: 4px solid #faad14; padding: 12px; border-radius: 4px; color: var(--alert-warn-color); }
.alert-error { background: var(--alert-error-bg); border: 1px solid var(--alert-error-border); color: var(--alert-error-color); }
.alert-success { background: var(--alert-success-bg); border: 1px solid var(--alert-success-border); color: var(--alert-success-color); }

/* ===== Detail grid ===== */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.detail-item { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--detail-border); font-size: 14px; }
.detail-item .label { color: var(--detail-label); }
.detail-item .value { font-weight: 500; color: var(--detail-value); }
.detail-item.full { grid-column: 1 / -1; }

/* ===== Login page ===== */
.login-page { min-height: 100vh; display: flex; justify-content: center; align-items: center; background: var(--login-gradient); transition: background .3s; }
.login-card { background: var(--login-card-bg); border-radius: 12px; padding: 32px; width: 100%; max-width: 400px; box-shadow: var(--login-card-shadow); transition: background .3s, box-shadow .3s; }
.login-card h1 { text-align: center; margin-bottom: 4px; font-size: 22px; color: var(--text-heading); }
.login-card .subtitle { text-align: center; color: var(--stat-label-color); font-size: 13px; margin-bottom: 24px; }
.login-card .icon { text-align: center; font-size: 40px; margin-bottom: 12px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .form-group label { display: block; font-size: 13px; color: var(--stat-label-color); margin-bottom: 4px; }
.login-card .form-group input { width: 100%; padding: 8px 12px; border: 1px solid var(--input-border); border-radius: 6px; font-size: 14px; height: 40px; background: var(--input-bg); color: var(--input-color); transition: background .3s, border-color .3s, color .3s; }
.login-card .form-group input:focus { border-color: #40a9ff; outline: none; box-shadow: 0 0 0 2px rgba(24,144,255,.2); }
.login-card .btn-primary { width: 100%; padding: 8px; margin-top: 8px; justify-content: center; height: 40px; }
.footer-text { text-align: center; margin-top: 16px; font-size: 11px; color: var(--footer-text); }

/* ===== Modal ===== */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--modal-overlay); z-index: 1000; justify-content: center; align-items: center; }
.modal-overlay.show { display: flex; }
.modal { background: var(--modal-bg); border-radius: 8px; width: 90%; max-width: 700px; max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 4px 20px rgba(0,0,0,.15); transition: background .3s; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--modal-border); display: flex; justify-content: space-between; align-items: center; transition: border-color .3s; flex-shrink: 0; }
.modal-header h3 { font-size: 16px; margin: 0; color: var(--text-heading); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--stat-label-color); padding: 0 4px; line-height: 1; }
.modal-close:hover { color: var(--text-color); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--modal-border); text-align: right; display: flex; gap: 8px; justify-content: flex-end; transition: border-color .3s; flex-shrink: 0; }

/* ===== Loading ===== */
.loading { text-align: center; padding: 40px; color: var(--loading-color); }

/* ===== Mobile header ===== */
.mobile-header { display: none; align-items: center; gap: 12px; padding: 12px 16px; background: var(--card-bg); border-bottom: 1px solid var(--card-border); position: sticky; top: 0; z-index: 100; }
.mobile-menu-btn { background: none; border: none; color: var(--text-color); cursor: pointer; display: flex; align-items: center; padding: 4px; border-radius: 4px; }
.mobile-menu-btn:hover { background: var(--sidebar-hover-bg); }
.mobile-header-title { font-size: 16px; font-weight: 600; color: var(--text-heading); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { width: 260px !important; transform: translateX(-100%); transition: transform .25s; box-shadow: 4px 0 16px rgba(0,0,0,.2); }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { width: 260px !important; }
  .sidebar.collapsed .sidebar-title { opacity: 1; width: auto; flex: 1; }
  .sidebar.collapsed .menu-text { opacity: 1; width: auto; }
  .sidebar.collapsed .sidebar-body a { justify-content: flex-start; padding: 10px 16px; }
  .sidebar.collapsed .sidebar-user { display: block; }
  .sidebar.collapsed .sidebar-actions { justify-content: flex-end; width: auto; }
  .sidebar.collapsed .sidebar-collapse-btn { transform: none; }
  .sidebar.collapsed .sidebar-body a.active { border-left: 3px solid #1890ff; }
  .sidebar-close-btn { display: flex; }
  .sidebar-collapse-btn { display: none; }
  .main-content { margin-left: 0 !important; }
  .mobile-header { display: flex; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
  .form-row > div { width: 100%; min-width: 0; max-width: none; box-sizing: border-box; }
  .form-row input[type="number"], .form-row input[type="text"], .form-row select { width: 100% !important; min-width: 0 !important; height: 36px !important; font-size: 14px !important; box-sizing: border-box; background: var(--card-bg) !important; border: 1.5px solid var(--input-border) !important; }
  .form-row select { min-width: 0 !important; }
  .form-row label { font-size: 12px !important; margin-bottom: 2px !important; color: var(--text-heading) !important; font-weight: 500; }
  .card-body { padding: 12px; overflow: hidden; }
  .main-content { padding: 12px; max-width: 100vw; overflow-x: hidden; }

  /* Filter row on mobile */
  .filter-row { width: 100%; flex-wrap: wrap; }
  .filter-row input[type="date"] { flex: 1; min-width: 0; height: 36px; font-size: 14px; box-sizing: border-box; }
  .filter-row .btn { flex: 0 0 auto; }

  /* Action buttons in a row on mobile */
  .form-row:has(.btn) { flex-direction: row !important; flex-wrap: wrap; gap: 8px; }
  .form-row .btn { flex: 1; min-width: 80px; text-align: center; white-space: nowrap; font-size: 13px; padding: 8px 6px; }
  .form-row .btn svg { margin-right: 4px; vertical-align: middle; }

  /* Modal footer buttons on mobile */
  .modal-footer { flex-direction: column; gap: 8px; }
  .modal-footer > div { width: 100%; display: flex; gap: 8px; }
  .modal-footer .btn { flex: 1; text-align: center; font-size: 15px; padding: 12px 10px; justify-content: center; min-height: 44px; }

  /* Tables as cards on mobile */
  .table-wrap { overflow-x: visible; }
  .table-wrap table, .table { min-width: 0; }
  .table, .table thead, .table tbody, .table tr, .table th, .table td { display: block; }
  .table thead { display: none; }
  .table tr {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    box-shadow: var(--card-shadow);
  }
  .table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border: none;
    font-size: 13px;
    white-space: normal;
  }
  .table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--stat-label-color);
    font-size: 12px;
    margin-right: 8px;
    flex-shrink: 0;
  }
  .table td:not(:last-child) {
    border-bottom: 1px solid var(--table-border);
  }
  .table tr:hover td { background: transparent; }

  /* Actions cell on mobile — row of icons */
  .table td.actions-cell { display: flex; justify-content: flex-end; gap: 12px; padding: 8px 0; border-bottom: none !important; }
  .table td.actions-cell::before { display: none; }
  .table td.actions-cell .btn-link { padding: 6px; }

  /* Cards full width */
  .card { overflow: hidden; }

  /* Filter bar wrap */
  .filter-bar { flex-wrap: wrap; gap: 8px; }
  .filter-bar .btn { flex: 1; min-width: 0; }

  /* Modal fullscreen on mobile */
  .modal { width: 95%; max-height: 90vh; margin: 5vh auto; }
  .modal-body { max-height: 60vh; }
}

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  pointer-events: auto;
  animation: toast-in .3s ease;
  max-width: 360px;
}

.toast-info { background: #1890ff; }
.toast-success { background: #52c41a; }
.toast-warning { background: #faad14; color: #333; }
.toast-error { background: #ff4d4f; }

.toast-hide {
  animation: toast-out .3s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(100%); }
}
