/* Toshin-Portal - Base Styles (T-Series Design Guidelines) */

:root {
  /* Colors - Primary */
  --primary: #0ea5e9;
  --primary-hover: #0284c7;
  --primary-light: #e0f2fe;

  /* Colors - Semantic */
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ff0303;
  --danger-hover: #e00000;

  /* Colors - Neutral */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-500: #64748b;
  --gray-700: #1e293b;
  --gray-900: #1e293b;
  --text-muted: #94a3b8;

  /* Border Radius */
  --radius: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
  --shadow-xl: 0 20px 40px rgba(0,0,0,0.15);
  --shadow-focus: 0 0 0 3px rgba(14, 165, 233, 0.15);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.6;
  min-height: 100vh;
}

/* Layout */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

@media (min-width: 768px) {
  .container {
    padding: 0 24px;
  }
}

@media (min-width: 1024px) {
  .container {
    padding: 0 32px;
  }
}

.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-header h1 {
  font-size: 1.5rem;
  color: var(--gray-900);
  margin-bottom: 0.5rem;
}

.auth-header p {
  color: var(--gray-500);
  font-size: 0.875rem;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--gray-700);
  margin-bottom: 0.25rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
}

.form-input.error {
  border-color: var(--danger);
}

.form-input.success {
  border-color: var(--success);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

.form-error {
  font-size: 0.75rem;
  color: var(--danger);
  margin-top: 0.25rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:focus {
  box-shadow: var(--shadow-focus);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-danger:focus {
  box-shadow: 0 0 0 3px rgba(255, 3, 3, 0.15);
}

.btn-secondary {
  background: white;
  color: var(--primary);
  border-color: var(--primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--primary-light);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.75rem;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
}

/* Links */
.link {
  color: var(--primary);
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}

/* OAuth Divider */
.auth-divider {
  display: flex;
  align-items: center;
  margin: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--gray-200);
}

.auth-divider span {
  padding: 0 1rem;
}

/* Google Login Button */
.btn-google {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  font-weight: 500;
  padding: 10px 16px;
}

.btn-google:hover {
  background: var(--gray-50);
  border-color: var(--gray-500);
}

.btn-google:focus {
  box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.15);
}

.btn-google svg {
  flex-shrink: 0;
}

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.875rem;
  color: var(--gray-500);
}

/* Alerts */
.alert {
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.alert-error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.alert-success {
  background: #f0fdf4;
  color: var(--success);
  border: 1px solid #bbf7d0;
}

.alert-warning {
  background: #fffbeb;
  color: var(--warning);
  border: 1px solid #fde68a;
}

/* Header/Nav */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 64px;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  box-shadow: var(--shadow);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--gray-900);
  text-decoration: none;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--gray-700);
  font-size: 0.875rem;
}

/* Icon Button */
.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--gray-100);
  border: none;
  cursor: pointer;
  transition: background-color 0.2s;
  text-decoration: none;
  color: var(--gray-700);
}

.icon-btn:hover {
  background: var(--gray-200);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* User Dropdown */
.user-dropdown {
  position: relative;
}

.user-dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 0.5rem;
  min-width: 200px;
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--gray-200);
  z-index: 100;
}

.user-dropdown-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-dropdown-header svg {
  width: 20px;
  height: 20px;
  color: var(--gray-500);
}

.user-dropdown-header span {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--gray-900);
}

.user-dropdown-body {
  padding: 0.75rem 1rem;
}

.user-dropdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  padding: 0.25rem 0;
}

.user-dropdown-row + .user-dropdown-row {
  border-top: 1px solid var(--gray-100);
  margin-top: 0.25rem;
  padding-top: 0.5rem;
}

.user-dropdown-label {
  color: var(--gray-500);
}

.user-dropdown-value {
  font-weight: 500;
  color: var(--gray-900);
}

/* Cards */
.card {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--gray-200);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
}

/* Layout Toolbar */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.layout-toolbar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.layout-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: white;
  cursor: pointer;
  color: var(--gray-500);
  transition: all 0.2s;
}

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

.layout-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* App Grid */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.app-grid.cols-1 {
  grid-template-columns: 1fr;
}

.app-grid.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.app-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 767px) {
  .app-grid.cols-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 399px) {
  .app-grid.cols-2,
  .app-grid.cols-3 {
    grid-template-columns: 1fr;
  }
}

.app-card {
  background: var(--primary-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  transition: all var(--transition-normal);
  text-decoration: none;
  color: inherit;
  position: relative;
}

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

.app-icon {
  width: 48px;
  height: 48px;
  background: var(--gray-100);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.app-info {
  min-width: 0;
}

.app-info h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-info p {
  font-size: 0.875rem;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Drag Handle */
.drag-handle {
  cursor: grab;
  color: var(--gray-300);
  margin-left: auto;
  padding: 4px;
  flex-shrink: 0;
}

.drag-handle:hover {
  color: var(--gray-500);
}

.drag-handle:active {
  cursor: grabbing;
}

/* SortableJS States */
.app-card.sortable-ghost {
  opacity: 0.3;
  background: var(--gray-100);
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.app-card.sortable-chosen {
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
  transform: scale(1.02);
  transition: box-shadow 0.2s, transform 0.2s;
}

.app-card.sortable-drag {
  box-shadow: 0 12px 32px rgba(0,0,0,0.2);
  opacity: 0.9;
}

/* Favorite Button */
.favorite-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-300);
  transition: color 0.2s;
  z-index: 10;
  padding: 2px 4px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.favorite-btn:hover {
  color: var(--warning);
}

.favorite-btn.active {
  color: var(--warning);
}

.app-card.is-favorite {
  background: #ffe4e6;
}

#appGrid .app-card:not(.is-favorite) .drag-handle {
  display: none;
}

/* Section Layout */
.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0;
}

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

.portal-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--gray-200);
}

/* Bookmark Card Actions */
.bookmark-card {
  background: #fef9e7;
}

.bookmark-card .card-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.bookmark-card:hover .card-actions {
  opacity: 1;
}

.card-action-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  background: var(--gray-100);
  color: var(--gray-500);
  transition: all 0.2s;
}

.card-action-btn:hover {
  background: var(--gray-200);
  color: var(--gray-700);
}

.card-action-btn.delete:hover {
  background: #fee2e2;
  color: var(--danger);
}

/* Tables */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
}

td {
  text-align: left;
  padding: 16px;
  font-size: 0.875rem;
  color: var(--gray-900);
  border-bottom: 1px solid var(--gray-200);
}

tbody tr:hover {
  background: var(--gray-50);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-admin {
  background: #fef3c7;
  color: #92400e;
}

.badge-manager {
  background: #dbeafe;
  color: #1e40af;
}

.badge-user {
  background: var(--gray-100);
  color: var(--gray-700);
}

.badge-active {
  background: #dcfce7;
  color: #166534;
}

.badge-inactive {
  background: #fee2e2;
  color: #991b1b;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 1.5rem;
}

.tab {
  padding: 0.75rem 1rem;
  border: none;
  background: none;
  font-size: 0.875rem;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--gray-700);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modal-enter 0.3s ease;
}

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 1px solid var(--gray-200);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius);
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-normal);
  line-height: 1;
}

.modal-close:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
}

/* Page Layout */
.page {
  padding-top: 2rem;
  padding-bottom: 2rem;
}

.page-header {
  margin-bottom: 2rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.page-subtitle {
  color: var(--gray-500);
}

/* Loading */
.loading {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* Utilities */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* ========================================
   Icon Picker
   ======================================== */

.icon-picker-tabs {
  display: flex;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.icon-picker-tab {
  flex: 1;
  padding: 6px 12px;
  border: none;
  background: white;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--gray-500);
  transition: all 0.15s;
}

.icon-picker-tab:hover {
  background: var(--gray-50);
}

.icon-picker-tab.active {
  background: var(--primary);
  color: white;
}

.icon-picker-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  min-height: 40px;
}

.icon-picker-preview-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 1.25rem;
}

.icon-picker-preview-icon svg {
  width: 22px;
  height: 22px;
}

.icon-picker-preview-label {
  font-size: 0.8rem;
  color: var(--gray-500);
  flex: 1;
}

.icon-picker-clear-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--gray-500);
  padding: 2px 6px;
  border-radius: 4px;
  display: none;
}

.icon-picker-clear-btn:hover {
  background: var(--gray-200);
  color: var(--gray-700);
}

.icon-picker-search {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.icon-picker-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 8px;
}

.icon-picker-item {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s;
  background: none;
  padding: 0;
  color: var(--gray-700);
}

.icon-picker-item:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.icon-picker-item.selected {
  background: var(--primary);
  color: white;
}

.icon-picker-item svg {
  width: 20px;
  height: 20px;
}

.icon-picker-hint {
  font-size: 0.7rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

.icon-picker-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 1rem;
  color: var(--gray-500);
  font-size: 0.8rem;
}

.icon-picker-emoji-input {
  font-size: 1.25rem;
}

/* カード内 Lucide SVG 表示 */
.app-icon svg {
  width: 24px;
  height: 24px;
  stroke: var(--gray-700);
}
