/* KI Link Shortener - Dashboard Styles */

:root {
  --primary: #4285f4;
  --primary-dark: #3367d6;
  --success: #34a853;
  --success-dark: #2d8e47;
  --error: #ea4335;
  --error-light: #fce8e6;
  --warning: #fbbc05;
  --surface: #ffffff;
  --background: #f5f5f5;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-disabled: #999999;
  --border: #e0e0e0;
  --border-light: #f0f0f0;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-elevated: 0 4px 12px rgba(0, 0, 0, 0.15);
}

* {
  box-sizing: border-box;
}

/* Ensure hidden attribute works with display properties */
[hidden] {
  display: none !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--text-primary);
  min-height: 100vh;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-email {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Auth Section */
.auth-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 100px);
  padding: 24px;
}

.auth-section p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

.btn:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

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

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

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

.btn-text {
  background: none;
  color: var(--primary);
  padding: 8px 12px;
}

.btn-text:hover:not(:disabled) {
  background: rgba(66, 133, 244, 0.1);
}

.btn-icon {
  background: none;
  border: none;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-secondary);
}

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

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
}

.google-btn:hover {
  background: var(--background);
  box-shadow: var(--shadow);
}

.google-btn svg {
  width: 18px;
  height: 18px;
}

/* Main Container */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
  color: var(--text-primary);
}

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

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-input {
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  min-width: 200px;
}

.filter-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

.filter-input::placeholder {
  color: var(--text-disabled);
}

.filter-count {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Data Table */
.table-container {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 800px;
}

thead {
  background: var(--background);
}

th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  color: var(--text-primary);
}

th .sort-icon {
  margin-left: 4px;
  opacity: 0.3;
}

th.sorted .sort-icon {
  opacity: 1;
  color: var(--primary);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

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

tr:hover {
  background: rgba(66, 133, 244, 0.04);
}

tr.expired {
  opacity: 0.6;
}

tr.expired .short-url-cell {
  text-decoration: line-through;
}

.short-url-cell {
  font-family: monospace;
  font-size: 13px;
}

.short-url-cell a {
  color: var(--primary);
  text-decoration: none;
}

.short-url-cell a:hover {
  text-decoration: underline;
}

.target-url-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-secondary);
}

.project-cell {
  font-size: 13px;
}

.project-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--background);
  border-radius: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.clicks-cell {
  font-family: monospace;
  font-size: 13px;
  text-align: right;
}

.date-cell {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.creator-cell {
  font-size: 13px;
  color: var(--text-secondary);
}

.actions-cell {
  white-space: nowrap;
  text-align: right;
}

.expired-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--error-light);
  color: var(--error);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  margin-left: 8px;
}

/* Expired Links Separator */
.expired-separator td {
  background: var(--background);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12px;
  padding: 8px 16px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.expired-separator:hover {
  background: var(--background);
}

/* QR Code Modal */
.qr-dialog {
  max-width: 360px;
}

.qr-dialog-body {
  text-align: center;
}

.qr-url {
  font-family: monospace;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--background);
  padding: 8px 12px;
  border-radius: 4px;
  word-break: break-all;
  margin-bottom: 16px;
}

#qrCanvas {
  display: block;
  margin: 0 auto;
  border-radius: 4px;
}

/* QR Button in table */
.btn-qr {
  color: var(--text-secondary);
}

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

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state h3 {
  margin: 0 0 8px 0;
  font-size: 16px;
  color: var(--text-primary);
}

.empty-state p {
  margin: 0;
}

/* Loading State */
.loading-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

/* Floating Action Button */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  box-shadow: var(--shadow-elevated);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
  z-index: 50;
}

.fab:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.fab:focus {
  outline: 2px solid var(--primary);
  outline-offset: 4px;
}

.fab svg {
  width: 24px;
  height: 24px;
}

/* Dialog / Modal */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

.dialog-overlay[hidden] {
  display: none;
}

.dialog {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow-elevated);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.dialog-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.dialog-body {
  padding: 24px;
}

.dialog-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Form */
.form-group {
  margin-bottom: 20px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.form-label.required::after {
  content: " *";
  color: var(--error);
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: border-color 0.2s, outline 0.2s;
}

.form-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

.form-input::placeholder {
  color: var(--text-disabled);
}

.form-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.form-warning {
  display: block;
  color: var(--error);
  background: var(--error-light);
  padding: 8px 12px;
  border-radius: 4px;
  border-left: 3px solid var(--error);
  line-height: 1.4;
}

.form-warning[hidden] {
  display: none;
}

textarea.form-input {
  min-height: 80px;
  resize: vertical;
}

/* Radio Group for Short Code Selection */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: normal;
}

.radio-label input[type="radio"] {
  margin: 0;
  cursor: pointer;
}

.custom-code-input {
  width: 180px;
  padding: 6px 10px;
  font-size: 13px;
  margin-left: 4px;
}

.custom-code-input:disabled {
  background: var(--background);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-primary);
  color: white;
  padding: 12px 16px;
  border-radius: 4px;
  box-shadow: var(--shadow-elevated);
  font-size: 14px;
  min-width: 250px;
  max-width: 400px;
  animation: slideIn 0.3s ease;
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--error);
}

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

/* Responsive */
@media (max-width: 768px) {
  .header {
    padding: 12px 16px;
  }

  .header h1 {
    font-size: 16px;
  }

  .main-container {
    padding: 16px;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    padding: 12px 16px;
    white-space: nowrap;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-input {
    min-width: auto;
    width: 100%;
  }

  .fab {
    bottom: 16px;
    right: 16px;
  }

  .dialog {
    max-width: 100%;
    margin: 16px;
  }

  .user-email {
    display: none;
  }
}
