@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* iPadOS Color Palette */
  --color-bg: #F2F2F7;
  --color-text: #3D2C2E;
  --color-text-secondary: #8A8A8A;
  --color-accent: #E87A00;
  --color-accent-hover: #d97000;
  --color-accent-light: rgba(232, 122, 0, 0.08);
  --color-card: #FFFFFF;
  --color-separator: #E5E5EA;
  --color-border: #E5E5EA;
  
  /* Spacing System */
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 20px;
  --space-xl: 24px;
  --space-2xl: 32px;
  
  /* Border Radius - iPadOS Style */
  --radius-icon: 6px;
  --radius-card: 10px;
  --radius-pill: 9999px;
  
  /* Shadows - iPadOS Depth */
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-card-hover: 0 2px 4px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.08);
  
  /* Typography Scale */
  --text-caption: 0.6875rem;  /* 11px - group labels */
  --text-xs: 0.8125rem;       /* 13px - secondary */
  --text-sm: 0.9375rem;       /* 15px - body */
  --text-base: 1.0625rem;     /* 17px - list items */
  --text-lg: 1.25rem;         /* 20px - page titles */
  --text-xl: 1.75rem;         /* 28px - large titles */
  --text-2xl: 2.125rem;       /* 34px - hero */
  
  /* Transitions - iPadOS Feel */
  --transition: all 0.2s ease-in-out;
}

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

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

button,
a,
input[type="submit"],
input[type="button"] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ========== iPadOS Two-Pane Layout ========== */
.layout {
  display: flex;
  min-height: 100dvh;
  background: var(--color-bg);
  padding: var(--space-lg);
  gap: var(--space-lg);
}

/* Mobile Header with Hamburger */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  background: var(--color-card);
  border-radius: 0;
  box-shadow: var(--shadow-card);
  position: sticky;
  top: 0;
  z-index: 200;
}

.mobile-header-brand {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--color-text);
}

.hamburger-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
  z-index: 10;
}

.hamburger-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.hamburger-btn:active {
  transform: scale(0.95);
  background: rgba(0, 0, 0, 0.08);
}

.hamburger-btn svg {
  width: 24px;
  height: 24px;
  color: var(--color-text);
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  pointer-events: none;
}

/* Sidebar Overlay (Mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  cursor: pointer;
  touch-action: manipulation;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-overlay:not(.active) {
  pointer-events: none;
}

/* Sidebar - White Rounded Card */
.sidebar {
  width: 260px;
  background: var(--color-card);
  border-radius: 12px;
  padding: var(--space-md);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  position: sticky;
  top: var(--space-lg);
  flex-shrink: 0;
  height: calc(100vh - 60px);
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.brand {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--color-text);
  padding: 0 4px;
}

.close-sidebar-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.close-sidebar-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.close-sidebar-btn:active {
  background: rgba(0, 0, 0, 0.08);
  transform: scale(0.95);
}

.close-sidebar-btn svg {
  width: 20px;
  height: 20px;
  color: var(--color-text);
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  pointer-events: none;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 12px;
  min-height: 44px;
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 400;
  border-radius: 8px;
  transition: var(--transition);
}

.nav-link:hover {
  background: rgba(0, 0, 0, 0.04);
}

.nav-link.active {
  background: var(--color-separator);
  font-weight: 500;
}

.nav-link:active {
  transform: scale(0.98);
}

/* Feather Icons in Sidebar - No colored container */
.nav-link svg {
  width: 20px;
  height: 20px;
  color: var(--color-text);
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

.nav-link.active svg {
  stroke-width: 2.5;
}

/* Main Content Pane - Scrollable */
.content {
  flex: 1;
  min-width: 0;
}

/* ========== Mobile Responsive ========== */
@media (max-width: 768px) {
  body {
    padding: 0;
    margin: 0;
  }
  
  .layout {
    display: block;
    padding: var(--space-md);
    padding-top: 0;
  }
  
  /* Show mobile header */
  .mobile-header {
    display: flex;
    margin-bottom: var(--space-md);
  }
  
  /* Hide desktop sidebar, show as overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85%;
    border-radius: 0;
    z-index: 400;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
  }
  
  .sidebar.active {
    transform: translateX(0);
  }
  
  .sidebar-overlay {
    display: block;
  }
  
  /* Show close button in sidebar */
  .close-sidebar-btn {
    display: flex;
  }
  
  /* Content takes full width */
  .content {
    width: 100%;
  }
  
  /* Mobile Form Layout - Complete Redesign */
  .form {
    gap: 0 !important;
  }
  
  .group {
    margin-bottom: var(--space-lg);
  }
  
  .group:last-child {
    margin-bottom: 0;
  }
  
  .group-label {
    margin: 0 0 var(--space-xs) 0;
    padding: 0;
  }
  
  .form-group {
    border-radius: 10px;
    overflow: hidden;
  }
  
  .form-row {
    display: block !important;
    padding: var(--space-md) !important;
    margin: 0 !important;
    border-bottom: 0.5px solid var(--color-separator);
  }
  
  .form-row:last-child {
    border-bottom: none;
  }
  
  .label {
    display: block !important;
    min-width: auto !important;
    width: 100% !important;
    margin: 0 0 var(--space-xs) 0 !important;
    padding: 0 !important;
    font-size: var(--text-sm) !important;
    font-weight: 600 !important;
    color: var(--color-text) !important;
    text-align: left !important;
  }
  
  .input,
  textarea.input,
  select.input {
    display: block !important;
    width: 100% !important;
    flex: none !important;
    margin: 0 !important;
    padding: 10px 12px !important;
    font-size: var(--text-base) !important;
    text-align: left !important;
    background: var(--color-bg) !important;
    border: 1px solid var(--color-separator) !important;
    border-radius: 8px !important;
    line-height: 1.4 !important;
  }
  
  textarea.input {
    min-height: 100px !important;
    resize: vertical;
  }
  
  .input:focus,
  textarea.input:focus,
  select.input:focus {
    background: var(--color-card) !important;
    border-color: var(--color-accent) !important;
    outline: none;
  }
  
  /* Stack cards vertically */
  .cards {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  
  .card {
    padding: var(--space-lg) !important;
  }
  
  /* Buttons stack on mobile */
  .form-actions {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 0 !important;
    margin: var(--space-lg) 0 0 0 !important;
    gap: var(--space-sm) !important;
  }
  
  .btn {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 12px 24px !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Page header stacks */
  .page-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: var(--space-md) !important;
    margin-bottom: var(--space-lg) !important;
  }
  
  .page-header h1 {
    font-size: var(--text-xl) !important;
  }
  
  /* Content padding on mobile */
  .content {
    padding: var(--space-md) !important;
  }
  
  /* Table responsive */
  .table-wrap {
    margin: 0 -#{var(--space-md)};
    border-radius: 0;
  }
}

/* ========== Page Header - iPadOS Large Title ========== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.page-header h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
  color: var(--color-text);
}

.page-header .sub {
  margin-top: 4px;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  font-weight: 400;
}

@media (max-width: 640px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-md);
  }
}

/* ========== Grouped List Cards - iPadOS Style ========== */
.group {
  margin-bottom: var(--space-2xl);
}

.group-label {
  font-size: var(--text-caption);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  margin: 0 var(--space-md) var(--space-xs);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-lg);
}

.card {
  background: var(--color-card);
  border-radius: var(--radius-card);
  padding: var(--space-lg) var(--space-xl);
  box-shadow: var(--shadow-card);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-card-hover);
}

.card-title {
  font-size: var(--text-caption);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xs);
}

.card-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--color-text);
  line-height: 1;
}

/* ========== List Items - Settings App Style ========== */
.list-group {
  background: var(--color-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  margin-bottom: var(--space-lg);
}

.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-md);
  min-height: 44px;
  transition: var(--transition);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.list-item:not(:last-child) {
  border-bottom: 0.5px solid var(--color-separator);
  margin: 0 var(--space-md);
  padding-left: 0;
  padding-right: 0;
}

.list-item:hover {
  background: rgba(0, 0, 0, 0.02);
}

.list-item:active {
  transform: scale(0.98);
}

/* List Item Icon */
.list-item-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-icon);
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.list-item-icon svg {
  width: 16px;
  height: 16px;
  color: white;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* List Item Content */
.list-item-content {
  flex: 1;
  min-width: 0;
}

.list-item-label {
  font-size: var(--text-base);
  font-weight: 400;
  color: var(--color-text);
  line-height: 1.3;
}

.list-item-detail {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin-top: 2px;
  line-height: 1.3;
}

/* Chevron for navigation items */
.list-item-chevron {
  width: 20px;
  height: 20px;
  color: var(--color-text-secondary);
  opacity: 0.4;
  flex-shrink: 0;
}

.list-item-chevron svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* ========== Forms - iPadOS Grouped Style ========== */
.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.form-group {
  background: var(--color-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.form-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-md);
  min-height: 44px;
}

.form-row:not(:last-child) {
  border-bottom: 0.5px solid var(--color-separator);
  margin: 0 var(--space-md);
  padding-left: 0;
  padding-right: 0;
}

.label {
  display: block;
  font-size: var(--text-base);
  font-weight: 400;
  color: var(--color-text);
  min-width: 120px;
  flex-shrink: 0;
}

.input,
textarea.input,
select.input {
  appearance: none;
  flex: 1;
  padding: var(--space-xs) var(--space-sm);
  min-height: 44px;
  font-family: inherit;
  font-size: var(--text-base);
  line-height: 1.4;
  color: var(--color-text);
  background: transparent;
  border: none;
  border-radius: 6px;
  transition: var(--transition);
  text-align: right;
}

.input:focus,
textarea.input:focus,
select.input:focus {
  outline: none;
  background: rgba(0, 0, 0, 0.02);
}

.input::placeholder {
  color: var(--color-text-secondary);
  opacity: 0.7;
}

textarea.input {
  resize: vertical;
  min-height: 80px;
  text-align: left;
  padding: var(--space-sm);
}

select.input {
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%238A8A8A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
  padding-right: var(--space-lg);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-top: var(--space-lg);
  padding: 0 var(--space-md);
}

/* ========== Buttons - iPadOS Pill Style ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-xl);
  min-height: 44px;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  color: var(--color-text);
  background: var(--color-card);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  box-shadow: var(--shadow-card);
}

.btn:hover {
  opacity: 0.8;
}

.btn:active {
  transform: scale(0.98);
}

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

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

.btn-delete {
  color: #dc2626;
  background: var(--color-card);
  border: 1px solid #fecaca;
}

.btn-delete:hover {
  background: #fef2f2;
  border-color: #dc2626;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Table action buttons */
.table .btn {
  padding: 6px 12px;
  font-size: var(--text-xs);
  min-height: auto;
}

/* ========== Tables - iPadOS List Style ========== */
.table-wrap {
  background: var(--color-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table thead {
  background: transparent;
}

.table th,
.table td {
  padding: var(--space-md) var(--space-md);
  text-align: left;
}

.table th {
  font-size: var(--text-caption);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  border-bottom: 0.5px solid var(--color-separator);
  background: transparent;
}

.table td {
  font-size: var(--text-base);
  color: var(--color-text);
}

.table tbody tr {
  transition: var(--transition);
}

.table tbody tr:not(:last-child) td {
  border-bottom: 0.5px solid var(--color-separator);
}

.table tbody tr:hover {
  background: rgba(0, 0, 0, 0.02);
}

@media (max-width: 768px) {
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
  }
  
  .table {
    min-width: 600px;
  }
  
  .table th,
  .table td {
    padding: var(--space-sm) var(--space-sm);
    font-size: var(--text-xs);
  }
  
  /* Stack table action buttons on mobile */
  .table .btn {
    display: block;
    width: 100%;
    margin-bottom: 4px;
    font-size: 11px;
    padding: 8px 10px;
  }
  
  .table .btn:last-child {
    margin-bottom: 0;
  }
}

/* ========== Notices ========== */
.notice {
  margin-top: var(--space-md);
  padding: var(--space-md);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  border-radius: var(--radius-card);
  background: rgba(0, 0, 0, 0.02);
  animation: fadeIn 0.3s ease-in;
}

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

/* ========== Modal ========== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.modal.active {
  display: flex;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1001;
}

.modal-content {
  position: relative;
  z-index: 1002;
  background: var(--color-card);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 0.5px solid var(--color-separator);
}

.modal-header h2 {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--color-text);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.04);
}

.modal-close svg {
  width: 18px;
  height: 18px;
  stroke: var(--color-text);
  stroke-width: 2;
  fill: none;
}

.modal-body {
  padding: var(--space-lg);
  overflow-y: auto;
  flex: 1;
}

/* Modal on mobile */
@media (max-width: 768px) {
  .modal {
    padding: 0;
  }
  
  .modal-content {
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    height: 100vh;
  }
}

/* ========== Utility Classes ========== */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

/* Responsive Helpers */
@media (max-width: 768px) {
  .hide-mobile {
    display: none;
  }
}

@media (min-width: 769px) {
  .hide-desktop {
    display: none;
  }
}
