/**
 * Ninox UI Components Update
 * Интеграция существующих компонентов с Ninox Design System
 */

/* ============================================
   BUTTONS - Обновление существующих кнопок
   ============================================ */

/* Sidebar Icon Button */
.sidebar-icon-button {
  width: 30px;
  height: 30px;
  border-radius: 4px;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  transition: background-color var(--transition-base), transform var(--transition-fast);
}

.sidebar-icon-button:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.sidebar-icon-button:active {
  transform: translateY(0);
}

/* Mode Button */
.mode-button {
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.92);
  border-radius: 4px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 500;
  text-align: left;
  min-height: 40px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  transition: background-color var(--transition-base), transform var(--transition-fast);
}

.mode-button:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.mode-button.active {
  background: rgba(255, 255, 255, 0.15);
}

.mode-button.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: #FFFFFF;
  border-radius: 0 2px 2px 0;
}

/* Toolbar Buttons */
.toolbar-button {
  height: 40px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toolbar-button.primary {
  background-color: #1C2C72;
  color: #FFFFFF;
}

.toolbar-button.primary:hover {
  background-color: #15235a;
  box-shadow: 0 4px 6px rgba(28, 44, 114, 0.3);
  transform: translateY(-1px);
}

.toolbar-button.secondary {
  background-color: #FFFFFF;
  color: #1C2C72;
  border-color: #ACAAB0;
}

.toolbar-button.secondary:hover {
  background-color: #F7F7FB;
  border-color: #4D5B91;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

.toolbar-button:disabled {
  background-color: #ACAAB0;
  color: #F7F7FB;
  cursor: not-allowed;
  transform: none;
}

/* Add Record Button */
.add-record-button {
  height: 40px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 4px;
  background-color: #1C2C72;
  color: #FFFFFF;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.add-record-button:hover {
  background-color: #15235a;
  box-shadow: 0 4px 6px rgba(28, 44, 114, 0.3);
  transform: translateY(-1px);
}

.add-record-button:active {
  transform: translateY(0);
}

/* Sidebar Add Button */
.sidebar-add-button {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 0;
  background: rgba(28, 44, 114, 0.2);
  color: #1C2C72;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.sidebar-add-button:hover {
  background: rgba(28, 44, 114, 0.3);
  transform: scale(1.05);
}

.sidebar-add-button:active {
  transform: scale(0.95);
}

/* ============================================
   FORM FIELDS - Обновление полей ввода
   ============================================ */

/* Sidebar Search */
.sidebar-search input {
  width: 100%;
  height: 40px;
  padding: 8px 12px;
  font-size: 14px;
  color: #140E14;
  background-color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(172, 170, 176, 0.5);
  border-radius: 4px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.sidebar-search input:hover {
  border-color: #4D5B91;
}

.sidebar-search input:focus {
  outline: none;
  border-color: #1C2C72;
  box-shadow: 0 0 0 3px rgba(28, 44, 114, 0.15);
}

.sidebar-search input::placeholder {
  color: #ACAAB0;
}

/* Record Form Inputs */
.record-form-fields input,
.record-form-fields select,
.record-form-fields textarea {
  width: 100%;
  height: 40px;
  padding: 8px 12px;
  font-size: 16px;
  color: #140E14;
  background-color: #FFFFFF;
  border: 1px solid #ACAAB0;
  border-radius: 4px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.record-form-fields input:hover,
.record-form-fields select:hover,
.record-form-fields textarea:hover {
  border-color: #4D5B91;
}

.record-form-fields input:focus,
.record-form-fields select:focus,
.record-form-fields textarea:focus {
  outline: none;
  border-color: #1C2C72;
  box-shadow: 0 0 0 3px rgba(28, 44, 114, 0.15);
}

.record-form-fields textarea {
  min-height: 100px;
  resize: vertical;
}

.record-form-fields select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237582A0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Error State */
.record-form-fields input.error,
.record-form-fields select.error,
.record-form-fields textarea.error {
  border-color: #E04F5F;
  background-color: rgba(224, 79, 95, 0.02);
}

.record-form-fields input.error:focus,
.record-form-fields select.error:focus,
.record-form-fields textarea.error:focus {
  box-shadow: 0 0 0 3px rgba(224, 79, 95, 0.15);
}

/* ============================================
   CHECKBOX & SWITCH
   ============================================ */

/* Custom Checkbox */
input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid #ACAAB0;
  border-radius: 3px;
  background-color: #FFFFFF;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  margin: 0;
}

input[type="checkbox"]:hover {
  border-color: #4D5B91;
}

input[type="checkbox"]:checked {
  background-color: #1C2C72;
  border-color: #1C2C72;
}

input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

input[type="checkbox"]:focus {
  outline: 2px solid #1C2C72;
  outline-offset: 2px;
}

input[type="checkbox"]:disabled {
  background-color: #F7F7FB;
  border-color: #E0E0E0;
  cursor: not-allowed;
}

/* Custom Switch/Toggle */
input[type="checkbox"].switch {
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background-color: #E0E0E0;
  border: none;
}

input[type="checkbox"].switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background-color: white;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease;
}

input[type="checkbox"].switch:checked {
  background-color: #1C2C72;
}

input[type="checkbox"].switch:checked::after {
  transform: translateX(20px);
}

/* ============================================
   TABLE STYLES
   ============================================ */

/* Grid Header */
.grid-header {
  background-color: #F7F7FB;
  border-bottom: 2px solid #E0E0E0;
}

.grid-header .grid-cell {
  padding: 12px 16px;
  font-weight: 600;
  color: #140E14;
  transition: background-color 0.15s ease;
}

.grid-header .grid-cell:hover {
  background-color: #F1F1F1;
}

/* Grid Rows */
.grid-row {
  transition: background-color 0.15s ease;
}

.grid-row:nth-child(odd) {
  background-color: #FFFFFF;
}

.grid-row:nth-child(even) {
  background-color: #F7F7FB;
}

.grid-row:hover {
  background-color: rgba(28, 44, 114, 0.04);
}

.grid-cell {
  padding: 12px 16px;
  border-bottom: 1px solid #F1F1F1;
  color: #140E14;
  font-size: 14px;
}

/* ============================================
   BADGES & STATUS
   ============================================ */

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  background-color: #F7F7FB;
  color: #7582A0;
}

.status-badge.primary {
  background-color: rgba(28, 44, 114, 0.1);
  color: #1C2C72;
}

.status-badge.success {
  background-color: rgba(69, 173, 99, 0.1);
  color: #45AD63;
}

.status-badge.error {
  background-color: rgba(224, 79, 95, 0.1);
  color: #E04F5F;
}

.status-badge.warning {
  background-color: rgba(245, 166, 35, 0.1);
  color: #F5A623;
}

/* Single Select Badge */
.single-select-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 12px;
  background: linear-gradient(135deg, #6f86cf 0%, #5671c0 100%);
  color: #FFFFFF;
}

/* ============================================
   TABS
   ============================================ */

.toolbar-tabs {
  display: flex;
  border-bottom: 1px solid #E0E0E0;
  background-color: #FFFFFF;
}

.toolbar-tab {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: #7582A0;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.toolbar-tab:hover {
  color: #140E14;
}

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

.toolbar-tab:focus {
  outline: 2px solid #1C2C72;
  outline-offset: -2px;
}

/* ============================================
   AVATAR
   ============================================ */

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6f86cf 0%, #5671c0 100%);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid #E0E0E0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.avatar-sm {
  width: 32px;
  height: 32px;
  font-size: 12px;
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: 18px;
}

/* ============================================
   NOTIFICATIONS
   ============================================ */

.notification {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  font-size: 14px;
  border-radius: 8px;
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.notification.success {
  background-color: rgba(69, 173, 99, 0.1);
  border-left: 4px solid #45AD63;
}

.notification.error {
  background-color: rgba(224, 79, 95, 0.1);
  border-left: 4px solid #E04F5F;
}

.notification.warning {
  background-color: rgba(245, 166, 35, 0.1);
  border-left: 4px solid #F5A623;
}

.notification.info {
  background-color: rgba(175, 189, 238, 0.1);
  border-left: 4px solid #AFBDEE;
}

/* ============================================
   TOOLTIP
   ============================================ */

[title] {
  position: relative;
}

[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 6px 10px;
  font-size: 12px;
  color: #FFFFFF;
  background-color: rgba(20, 14, 20, 0.9);
  border-radius: 4px;
  white-space: nowrap;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(-8px);
  }
}

/* ============================================
   LOADING SPINNER
   ============================================ */

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid #F7F7FB;
  border-top-color: #1C2C72;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 1px;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

/* Mobile (<=375px) */
@media (max-width: 375px) {
  .toolbar-button,
  .add-record-button {
    height: 36px;
    padding: 6px 12px;
    font-size: 13px;
  }
  
  .grid-cell {
    padding: 10px 12px;
    font-size: 13px;
  }
}

/* Tablet (768px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 240px 1fr;
  }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 32px;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid #1C2C72;
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
